amoghrajesh commented on code in PR #44241:
URL: https://github.com/apache/airflow/pull/44241#discussion_r1856673055
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -122,6 +125,44 @@ def ti_update_state(
)
elif isinstance(ti_patch_payload, TITerminalStatePayload):
query = TI.duration_expression_update(ti_patch_payload.end_date,
query, session.bind)
+ elif isinstance(ti_patch_payload, TIDeferredStatePayload):
+ trigger_row = Trigger(
+ classpath=ti_patch_payload.classpath,
+ kwargs=ti_patch_payload.kwargs,
+ created_date=ti_patch_payload.created_date,
+ )
+ session.add(trigger_row)
+ session.flush()
+
+ ti = session.query(TI).filter(TI.id == ti_id_str).one_or_none()
+
+ # Calculate timeout too if it was passed
+ trigger_timeout: datetime | None = None
+ if ti_patch_payload.timeout is not None:
+ trigger_timeout = timezone.utcnow() + ti_patch_payload.timeout
+ else:
+ trigger_timeout = None
+
+ # If an execution_timeout is set, set the timeout to the minimum of
+ # it and the trigger timeout
+ if ti.task:
+ execution_timeout = ti.task.execution_timeout
+ if execution_timeout:
+ if TYPE_CHECKING:
+ assert ti.start_date
+ if ti.trigger_timeout:
+ trigger_timeout = min(ti.start_date + execution_timeout,
ti.trigger_timeout)
+ else:
+ trigger_timeout = ti.start_date + execution_timeout
+
+ query = update(TI).where(TI.id == ti_id_str)
+ query = query.values(
+ state=State.DEFERRED,
+ trigger_id=trigger_row.id,
+ next_method=ti_patch_payload.next_method,
+ next_kwargs=ti_patch_payload.kwargs or {},
Review Comment:
Generally should never be None.
Pydantic also doesn't allow it through, removing this check
--
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]