Skip to content

Fix job abortion during worker graceful shutdown - #1603

Open
owenh000 wants to merge 1 commit into
procrastinate-org:mainfrom
owenh000:abort-job-during-worker-shutdown
Open

Fix job abortion during worker graceful shutdown#1603
owenh000 wants to merge 1 commit into
procrastinate-org:mainfrom
owenh000:abort-job-during-worker-shutdown

Conversation

@owenh000

@owenh000 owenh000 commented Jul 26, 2026

Copy link
Copy Markdown

During worker graceful shutdown, stop the "poll_jobs_to_abort" side task after running jobs have ended rather than before. Without this change, it is impossible to abort a running job via abort polling after a worker has been asked to stop.

Also add a test that fails without this change.

Closes #1598

Successful PR Checklist:

  • Tests
    • (not applicable?)
  • Documentation
    • (not applicable?)

PR label(s):

Summary by CodeRabbit

  • Bug Fixes

    • Improved graceful worker shutdown by staging side-task cancellation so running jobs can still be aborted during the shutdown window.
    • Enhanced shutdown behavior to complete cleanly after any pending job-abort polling activity.
  • Tests

    • Added an async unit test for aborting a running job while the worker begins graceful shutdown, verifying the job transitions to ABORTED.

@owenh000
owenh000 requested a review from a team as a code owner July 26, 2026 21:52
@github-actions github-actions Bot added the PR type: bugfix 🕵️ Contains bug fix label Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Worker shutdown keeps the abort-polling side task active while running jobs undergo graceful handling, then cancels it with the remaining side tasks. A unit test verifies that a running async job can be aborted after shutdown begins.

Changes

Graceful shutdown abort polling

Layer / File(s) Summary
Stage side-task cancellation during shutdown
procrastinate/worker.py, tests/unit/test_worker.py
Shutdown defers cancellation of poll_jobs_to_abort until graceful job handling completes, and tests that a running async job transitions to ABORTED during shutdown.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes defer abort polling until after shutdown waits, matching #1598's requirement to abort running jobs during graceful shutdown.
Out of Scope Changes check ✅ Passed All code changes are focused on graceful-shutdown abort polling and its regression test; no unrelated scope is evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing job abortion during graceful worker shutdown.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unit/test_worker.py`:
- Around line 608-625: Replace the fixed 20 ms sleeps in the worker shutdown and
abort assertions around start_worker and get_job_status_async with bounded
polling that repeatedly checks for the expected Status.DOING or Status.ABORTED
state until a timeout. Preserve the existing status assertions and await
run_task after cancellation, while ensuring the test fails clearly if the
expected state is not reached.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c587494a-b078-4557-8eab-e9b57450f02d

📥 Commits

Reviewing files that changed from the base of the PR and between c3c6f97 and 9e3dcca.

📒 Files selected for processing (2)
  • procrastinate/worker.py
  • tests/unit/test_worker.py

Comment thread tests/unit/test_worker.py
Comment thread procrastinate/worker.py Outdated
During worker graceful shutdown, stop the "poll_jobs_to_abort" side
task *after* running jobs have ended rather than before. Without this
change, it is impossible to abort a running job via abort polling after
a worker has been asked to stop.

Also add a test that fails without this change.

Closes <procrastinate-org#1598>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR type: bugfix 🕵️ Contains bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to abort running job while its worker is shutting down

2 participants