amoghrajesh commented on code in PR #77015:
URL: https://github.com/apache/airflow/pull/77015#discussion_r4715715635
##########
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:
Handled in 63c63b98121
##########
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:
Handled in 63c63b98121
##########
providers/databricks/src/airflow/providers/databricks/operators/databricks.py:
##########
@@ -1582,6 +1597,28 @@ def is_job_active(self, status: str) -> bool:
def is_job_succeeded(self, status: str) -> bool:
return is_run_succeeded(status)
+ def resume_failed_job(self, external_id: JsonValue, status: str, context:
Context) -> JsonValue | None:
+ # cancel_previous_runs keeps only the newest run going; reviving this
one would break that.
+ if status == RUN_NOT_FOUND_STATUS or self.cancel_previous_runs:
Review Comment:
Handled in 63c63b98121
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/durable_execution.py:
##########
@@ -57,8 +60,16 @@ def get_durable_execution(scope: TaskScopeDep, session:
SessionDep) -> DurableEx
)
if value is None:
return DurableExecutionResponse(tries=[])
- try:
- return DurableExecutionResponse.model_validate(json.loads(value))
- except ValidationError:
- # With [workers] state_store_backend set, the row holds only a
reference to the offloaded value.
+ record = json.loads(value)
+ # With [workers] state_store_backend set, the row holds only a reference
to the offloaded value.
Review Comment:
Handled in 63c63b98121
--
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]