jscheffl commented on code in PR #67118:
URL: https://github.com/apache/airflow/pull/67118#discussion_r3293214804


##########
task-sdk/src/airflow/sdk/bases/resumablemixin.py:
##########
@@ -0,0 +1,139 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Any
+
+if TYPE_CHECKING:
+    from airflow.sdk.definitions.context import Context
+    from airflow.sdk.types import Logger
+
+
+class ResumableJobMixin:
+    """
+    Mixin for operators that submit one long-running job to an external system 
and poll for completion.
+
+    On retry, reads the persisted external ID from task_state and reconnects 
to the existing job
+    instead of resubmitting from scratch. Reconnect can mean different for 
different kind of jobs.
+
+    Usage: call ``execute_resumable(context)`` from the operator's 
``execute()`` when reconnection
+    is supported.
+
+    Subclasses must implement the methods specific to their external system. 
The mixin owns
+    only ``execute_resumable()`` and the task_state read/write logic.
+
+    Example::
+
+        class MyOperator(ResumableJobMixin, BaseOperator):
+            external_id_key = "my_job_id"
+
+            def execute(self, context):
+                return self.execute_resumable(context)
+
+            def submit_job(self, context) -> str:
+                return self.hook.submit(...)
+
+            def get_job_status(self, external_id: str) -> str:
+                return self.hook.get_status(external_id)
+
+            def is_job_active(self, status: str) -> bool:
+                return status in ("RUNNING", "PENDING")

Review Comment:
   Okay, then I understand it after reading your comments. Maybe this should be 
expressed in interface contract then. The status this is any kind of string 
whatever the respective backend has, could be also a "ContainerCreating" or 
"Approval pending" or "Pizza was ordered, delivery will arrive in 20min"... 
very much based on specific backend.
   
   Can you express this in the docs?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to