amoghrajesh commented on code in PR #77015:
URL: https://github.com/apache/airflow/pull/77015#discussion_r4715706500


##########
task-sdk/docs/resumable-job-mixin.rst:
##########
@@ -102,7 +102,55 @@ to check the current state of the job:
   waiting.
 * If the job already completed successfully, the mixin calls 
``get_job_result`` and returns
   immediately without resubmitting.
-* If the job is in a terminal failure state, the mixin falls through and 
submits a fresh job.
+* If the job is in a terminal failure state and ``resume_on_retry`` is set, 
the mixin calls
+  ``resume_failed_job``. If that returns an identifier, the mixin polls it 
instead of starting over.
+  Otherwise it submits a fresh job.
+
+Resuming a failed job
+---------------------
+
+.. versionadded:: 3.5.0
+
+Some external systems can rerun a failed job from where it stopped, for 
example by repairing a
+Databricks run or calling ``redrive_execution`` on a Step Functions execution. 
To use that on retry,
+override the optional ``resume_failed_job`` method:
+
+``resume_failed_job(external_id, status, context)``
+    Ask the external system to resume the failed job. Return the identifier to 
poll, which can be the
+    same one or a new one. Return ``None`` to submit a fresh job instead. The 
default returns ``None``.
+
+If ``resume_failed_job`` raises, the engine may still have accepted the 
request, for example when
+the reply times out. Submitting a fresh job then would leave two jobs running. 
So the mixin reads
+the stored job's status again, up to ``resume_status_checks`` times (3 by 
default), waiting
+``resume_status_check_interval`` seconds (10 by default) between reads:
+
+- If the job is running or has succeeded, the mixin watches it instead of 
submitting a new one.
+- If the job still looks failed after every read, the mixin submits a fresh 
job.
+- If the status cannot be read, the try fails with the original error, and the 
next retry checks
+  again.
+
+This check only finds a job resumed under the stored identifier. An engine 
that resumes under a new

Review Comment:
   Updated: it now says the mixin resumes a failed job when the operator 
supports it and `resume_on_retry` is on, and otherwise submits a new one, with 
a link to the mixin page.



##########
task-sdk/src/airflow/sdk/bases/resumablejobmixin.py:
##########
@@ -238,15 +268,61 @@ def get_resume_decision(self, context: Context) -> 
ResumeDecision:
                 self._record_try(context, DurableDecision.ALREADY_SUCCEEDED, 
external_id, status="success")
                 return ResumeDecision("already_succeeded", external_id)
 
+            if self.resume_on_retry and self._can_resume_failed_job():
+                span.set_attribute("resumable.decision", "resume")
+                return ResumeDecision("resume", external_id, status)
+

Review Comment:
   Added a guard.



-- 
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