RehanAhmad25 commented on code in PR #76891:
URL: https://github.com/apache/airflow/pull/76891#discussion_r4546791962
##########
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:
The `TaskInstanceState.RUNNING` check and the updated state coverage look
great. Thanks for updating the docs as well! LGTM.
--
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]