Skip to content

Conversation

@chrisguidry
Copy link
Owner

When docket.cancel(key) is called for a task that's currently executing on a
worker, the worker now receives a signal via Redis pub/sub and cancels the
asyncio task. Tasks see standard asyncio.CancelledError, same as timeouts.

If a task catches and swallows the CancelledError, it continues to completion
normally - respecting the task's choice.

Also refactors mark_as_completed, mark_as_failed, and mark_as_cancelled
into a common _mark_as_terminal helper to reduce duplication.

Closes #183

🤖 Generated with Claude Code

When `docket.cancel(key)` is called for a task that's currently executing on a
worker, the worker now receives a signal via Redis pub/sub and cancels the
asyncio task. Tasks see standard `asyncio.CancelledError`, same as timeouts.

If a task catches and swallows the CancelledError, it continues to completion
normally - respecting the task's choice.

Also refactors `mark_as_completed`, `mark_as_failed`, and `mark_as_cancelled`
into a common `_mark_as_terminal` helper to reduce duplication.

Closes #183

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Dec 23, 2025

📚 Documentation has been built for this PR!

You can download the documentation directly here:
https://github.com/chrisguidry/docket/actions/runs/20465426459/artifacts/4954579619

@codecov-commenter
Copy link

codecov-commenter commented Dec 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (82f02a7) to head (ad1c4b0).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              main      #261    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           53        54     +1     
  Lines         8620      8873   +253     
  Branches       434       438     +4     
==========================================
+ Hits          8620      8873   +253     
Flag Coverage Δ
python-3.10 100.00% <100.00%> (ø)
python-3.11 98.76% <99.00%> (+<0.01%) ⬆️
python-3.12 100.00% <100.00%> (ø)
python-3.13 100.00% <100.00%> (ø)
python-3.14 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/docket/docket.py 100.00% <100.00%> (ø)
src/docket/execution.py 100.00% <100.00%> (ø)
src/docket/worker.py 100.00% <100.00%> (ø)
...s/concurrency_limits/test_errors_and_resilience.py 100.00% <100.00%> (ø)
tests/test_cancellation.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Verifies that cancelled tasks do not retry (even with Retry dependency)
and do not perpetuate (even with Perpetual dependency).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Best-effort cancellation of running tasks

3 participants