Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Sep 25, 2024
1 parent 46b3b5e commit d18b071
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pulpcore/tasking/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
delete_incomplete_resources,
dispatch_scheduled_tasks,
perform_task,
execute_task,
startup_hook,
)

Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d18b071

Please sign in to comment.