Skip to content

Move scheduling and cancelation db operation to atomic update requests - #104

Merged
badtst merged 6 commits into
mainfrom
fix/atomic-cancelation
Sep 8, 2026
Merged

badtst merged 6 commits into
mainfrom
fix/atomic-cancelation

Conversation

@badtst

@badtst badtst commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Description

Use atomic UPDATE statements for job cancellation/job scheduling instead of WITH FOR UPDATE statements which are noop on sqlite.

Atomic update statements are preffered to other solutions like exlusive transactions as they have a reliable behavior across the different backends and the logic performed within them is actually quite simple.

Improved testing for those possible race conditions:

  • introduce repeated tests where we concurrently run cancellation logic/scheduling logic
  • tests where we purposely interweave a cancel request in the middle of the scheduling logic

Changed

  • Minor refactor of the scheduler strategy logic for better separation of responsabilities
    • Each scheduling strategy is tasked with identifying the next schedulable job id
    • get_next_job interface tries to claim the job by setting scheduled_at datetime of the previously identified job id

@badtst
badtst marked this pull request as ready for review September 3, 2026 16:09
Comment on lines +154 to +155
(rather than on a fixed call count) keeps this test working regardless
of how many reads a strategy's candidate pick does.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Can we get rid of these chain of thoughts statement which are just remnant from debugging? Let's focus on what has been implemented and why

@badtst
badtst merged commit f3bd723 into main Sep 8, 2026
14 checks passed
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.

2 participants