Skip to content

Split run_task() into claim_task() and run_claimed_task() - #60

Merged
tokibito merged 1 commit into
mainfrom
split-run-task
Oct 2, 2026
Merged

tokibito merged 1 commit into
mainfrom
split-run-task

Conversation

@tokibito

@tokibito tokibito commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Refactor ahead of `--threads M` (#25). `run_task()` claimed the task and ran it in one call. A worker that fetches in one thread and runs in another needs the claim in the fetching thread, so that its next `fetch_task()` does not hand it the same READY row again, and the run in the executor thread.

`DatabaseTaskBackend` gains two public methods, and `run_task()` becomes one followed by the other:

  • `claim_task(db_task, worker_id=None)` moves a READY task to RUNNING and records the attempt, returning True if this call claimed it and False if it was no longer READY, in which case nothing was written. It is the former private claim with its docstring moved up; the private name stays as the implementation.
  • `run_claimed_task(db_task, worker_id=None)` is the run itself, for a task `claim_task()` has moved to RUNNING, with the same records, logs and signals as before.

Nothing that calls `run_task()` changes, and the existing tests pass unmodified on Python 3.13 / Django 6.0 and Python 3.14 / Django 6.1 with `-W error::DeprecationWarning`. Three tests are added for the two methods on their own and for `run_task()` being the two of them. A CHANGELOG line notes the new methods; existing projects need no changes.

Refs #25

run_task() claimed the task and ran it in one call. A worker that fetches
tasks in one thread and runs them in another needs the claim in the
fetching thread, so that its next fetch does not return the same READY row,
and the run elsewhere. The two steps are now public methods and run_task()
calls one and then the other; nothing that calls run_task() changes, and
the existing tests pass unmodified.

Refs #25
@tokibito
tokibito merged commit e7a1fd3 into main Oct 2, 2026
10 checks passed
@tokibito
tokibito deleted the split-run-task branch October 2, 2026 05:16
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.

1 participant