amoghrajesh commented on code in PR #45070:
URL: https://github.com/apache/airflow/pull/45070#discussion_r1891492029
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -354,3 +370,18 @@ def ti_put_rtif(
_update_rtif(task_instance, put_rtif_payload, session)
return {"message": "Rendered task instance fields successfully set"}
+
+
+def _is_eligible_to_retry(task_instance, task_retries: int):
+ """
+ Is task instance is eligible for retry.
+
+ :param task_instance: the task instance
+
+ :meta private:
+ """
+ if task_instance.state == State.RESTARTING:
+ # If a task is RESTARTING state it is always eligible for retry
+ return True
+
+ return task_retries and task_instance.try_number <= task_instance.max_tries
Review Comment:
Mainly a port over of
https://github.com/apache/airflow/blob/088242a911ba52f16a8c97df0d6dcb7e47ca1b73/airflow/models/taskinstance.py#L1053-L1072
because we do not have "task_instance" table entries in SDK anymore.
Tried splitting it too because we do not have "task_instance.task" here
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -296,8 +296,22 @@ def run(ti: RuntimeTaskInstance, log: Logger):
)
# TODO: Run task failure callbacks here
- except (AirflowTaskTimeout, AirflowException, AirflowTaskTerminated):
+ except AirflowTaskTerminated:
...
+ except (AirflowTaskTimeout, AirflowException):
+ # Couldn't load the task, don't know number of retries, guess
+ if not getattr(ti, "task", None):
+ # Let us set the task_retries to default = 0
+ msg = RetryTask(
+ end_date=datetime.now(tz=timezone.utc),
+ task_retries=0,
+ )
+ else:
+ msg = RetryTask(
+ end_date=datetime.now(tz=timezone.utc),
+ # is `or 0` needed?
+ task_retries=ti.task.retries or 0,
+ )
Review Comment:
As for the API and this PR, all we should care about is whether we should
retry or not. The task ran, complained that it needs to retry, so we send a
retry API call. The core logic of how retry works should be out of the scope of
this PR.
--
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]