jedcunningham commented on code in PR #30375:
URL: https://github.com/apache/airflow/pull/30375#discussion_r1166109290
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -1425,6 +1461,47 @@ def _send_sla_callbacks_to_processor(self, dag: DAG) ->
None:
)
self.job.executor.send_callback(request)
+ @provide_session
+ def _fail_tasks_stuck_in_queued(self, session: Session = NEW_SESSION) ->
None:
+ """
+ Mark tasks stuck in queued for longer than `task_queued_timeout` as
failed.
+
+ Tasks can get stuck in queued for a wide variety of reasons (e.g.
celery loses
+ track of a task, a cluster can't further scale up its workers, etc.),
but tasks
+ should not be stuck in queued for a long time. This will mark tasks
stuck in
+ queued for longer than `self._task_queued_timeout` as failed. If the
task has
+ available retries, it will be retried.
+ """
+ self.log.debug("Calling SchedulerJob._fail_tasks_stuck_in_queued
method")
+ for attempt in run_with_db_retries(logger=self.log):
+ with attempt:
+ self.log.debug(
+ "Running SchedulerJob._fail_tasks_stuck_in_queued with
retries. Try %d of %d",
+ attempt.retry_state.attempt_number,
+ MAX_DB_RETRIES,
+ )
+ try:
+ query = session.query(TI).filter(
+ TI.state == State.QUEUED,
+ TI.queued_dttm < (timezone.utcnow() -
timedelta(seconds=self._task_queued_timeout)),
Review Comment:
```suggestion
TI.queued_dttm < (timezone.utcnow() -
timedelta(seconds=self._task_queued_timeout)),
TI.queued_by_job_id == self.job_id,
```
Lets only look at this specific schedulers tasks.
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -1425,6 +1461,47 @@ def _send_sla_callbacks_to_processor(self, dag: DAG) ->
None:
)
self.job.executor.send_callback(request)
+ @provide_session
+ def _fail_tasks_stuck_in_queued(self, session: Session = NEW_SESSION) ->
None:
+ """
+ Mark tasks stuck in queued for longer than `task_queued_timeout` as
failed.
+
+ Tasks can get stuck in queued for a wide variety of reasons (e.g.
celery loses
+ track of a task, a cluster can't further scale up its workers, etc.),
but tasks
+ should not be stuck in queued for a long time. This will mark tasks
stuck in
+ queued for longer than `self._task_queued_timeout` as failed. If the
task has
+ available retries, it will be retried.
+ """
+ self.log.debug("Calling SchedulerJob._fail_tasks_stuck_in_queued
method")
+ for attempt in run_with_db_retries(logger=self.log):
+ with attempt:
+ self.log.debug(
+ "Running SchedulerJob._fail_tasks_stuck_in_queued with
retries. Try %d of %d",
+ attempt.retry_state.attempt_number,
+ MAX_DB_RETRIES,
+ )
+ try:
+ query = session.query(TI).filter(
+ TI.state == State.QUEUED,
+ TI.queued_dttm < (timezone.utcnow() -
timedelta(seconds=self._task_queued_timeout)),
+ )
+ tasks_stuck_in_queued: list[TaskInstance] = with_row_locks(
+ query, of=TI, session=session,
**skip_locked(session=session)
+ ).all()
Review Comment:
```suggestion
tasks_stuck_in_queued: list[TaskInstance] = query.all()
```
Which also means we don't need to lock rows.
--
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]