amoghrajesh commented on code in PR #76833:
URL: https://github.com/apache/airflow/pull/76833#discussion_r4616865038
##########
task-sdk/src/airflow/sdk/bases/resumablejobmixin.py:
##########
@@ -225,6 +254,51 @@ def persist_job_id(self, context: Context, external_id:
JsonValue) -> None:
external_id=external_id,
)
+ def _record_try(
+ self,
+ context: Context,
+ decision: DurableDecision,
+ external_id: JsonValue,
+ *,
+ job_finished: bool = False,
+ previous_external_id: JsonValue = None,
+ ) -> None:
+ """Record this try for the logs banner; a finished reconnect stores
the job's run time as saved."""
+ task_state_store = context.get("task_state_store")
+ if task_state_store is None:
+ return
+ try:
+ now = datetime.now(tz=UTC)
+ stored = task_state_store.get(DURABLE_RECORD_KEY)
+ record: dict[str, Any] = stored if isinstance(stored, dict) else {}
+ if decision in (DurableDecision.SUBMITTED,
DurableDecision.RESUBMITTED):
+ record["submitted_at"] = now.isoformat()
+ saved_seconds = None
+ if job_finished and record.get("submitted_at"):
+ saved_seconds = (now -
datetime.fromisoformat(record["submitted_at"])).total_seconds()
+ # Airflow states rather than the provider's raw status string, so
the UI can render them.
+ status = None
+ if decision == DurableDecision.RECONNECTED:
+ status = "success" if job_finished else "running"
+ elif decision == DurableDecision.ALREADY_SUCCEEDED:
+ status = "success"
+ try_number = getattr(context.get("ti"), "try_number", None)
+ record["tries"] = [t for t in record.get("tries", []) if
t.get("try_number") != try_number]
+ record["tries"].append(
+ {
+ "try_number": try_number,
+ "decision": decision.value,
+ "external_id": external_id,
+ "status": status,
+ "saved_seconds": saved_seconds,
+ **({"previous_external_id": previous_external_id} if
previous_external_id else {}),
+ }
+ )
+ task_state_store.set(DURABLE_RECORD_KEY, record)
Review Comment:
Yet to figure out cleanup of this, my first thought is `clear_on_success` I
think
--
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]