sjyangkevin commented on code in PR #76891:
URL: https://github.com/apache/airflow/pull/76891#discussion_r4543794412
##########
airflow-core/src/airflow/api_fastapi/execution_api/security.py:
##########
@@ -372,6 +374,31 @@ async def _require_live_attempt(token: ExecutionToken, *,
allow_callback: bool)
)
+async def is_execution_token_renewable(token: ExecutionToken) -> bool:
+ """
+ Tell whether the work an ``execution`` token was issued for is still
unfinished.
+
+ The subject is a task attempt, a callback, or ``ASSET_WATCHER_ID``, which
has no row and no
+ lifecycle. Any other subject is not renewable, including an attempt that
is finished, archived
+ or deleted, so its token expires on its own. This is not an admission
check: a finished attempt
+ still runs its success callbacks with the token it holds.
+ """
+ if token.id == ASSET_WATCHER_ID:
+ return True
+ async with create_session_async() as session:
+ attempt = (
+ await session.execute(
+ select(TaskInstance.state, TaskInstance.working_set)
+ .where(TaskInstance.id == token.id)
+ .execution_options(include_all_attempts=True)
+ )
+ ).one_or_none()
+ if attempt is not None:
+ return attempt.working_set is True and attempt.state not in
State.finished
Review Comment:
Thanks for the feedback. Renewal during the wait was not intended. It came
from the check being "not finished", and `DEFERRED` / `UP_FOR_RESCHEDULE` are
not finished states.
I updated the condition. A task token is now renewed only while the attempt
is the current try and is `running`. So it is no longer renewed while the
attempt is parked (`deferred`, `up_for_reschedule`, `awaiting_input`) or
waiting to start again (`scheduled`, `queued`).
`test_token_is_reissued_only_while_task_attempt_is_running` now covers every
task state, and only `running` is renewed.
This stops renewal during the wait, not after it. A resumed attempt keeps
the same ID, so an old token that has not yet expired when the attempt runs
again is renewed again. Tokens are still not revocable. I added this to the
docs.
Callbacks are unchanged, since they do not have a parked state.
--
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]