From 7fb9d324d79b71c168559a80bb3e52c7c47fa6f7 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Wed, 25 Sep 2024 18:03:55 -0300 Subject: [PATCH] wip --- pulpcore/tasking/worker.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pulpcore/tasking/worker.py b/pulpcore/tasking/worker.py index f7e0d355cb..dc41bf9137 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,16 @@ def iter_tasks(self): else: break + def get_short_task(self): + task = ( + Task.objects.filter(state__in=TASK_STATES.WAITING, unblocked_at__isnull=False) + .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 +437,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(