diff --git a/pulpcore/tasking/worker.py b/pulpcore/tasking/worker.py index f7e0d355cb..5dba246ae6 100644 --- a/pulpcore/tasking/worker.py +++ b/pulpcore/tasking/worker.py @@ -35,6 +35,7 @@ delete_incomplete_resources, dispatch_scheduled_tasks, perform_task, + execute_task, startup_hook, ) @@ -339,6 +340,18 @@ def iter_tasks(self): else: break + def get_short_task(self): + task = ( + Task.objects.filter( + state__in=TASK_STATES.WAITING, unblocked_at__isnull=False, immediate=True + ) + .order_by("pulp_created") + .first() + ) + with contextlib.suppress(AdvisoryLockError), task: + task.refresh_from_db() + yield task + def sleep(self): """Wait for signals on the wakeup channel while heart beating.""" @@ -426,6 +439,10 @@ def supervise_task(self, task): ) cancel_state = TASK_STATES.FAILED cancel_reason = "Aborted during worker shutdown." + + if short_task := self.get_short_task(): + execute_task(short_task) + task_process.join() if not cancel_state and task_process.exitcode != 0: _logger.warning(