Skip to content

Add optional cursor for run_at time on jobs#120

Merged
BBrannick merged 11 commits into
masterfrom
run-at-cursor
Jun 24, 2026
Merged

Add optional cursor for run_at time on jobs#120
BBrannick merged 11 commits into
masterfrom
run-at-cursor

Conversation

@BBrannick

Copy link
Copy Markdown
Contributor

This additional cursor can lead to more dead tuples/tombstones being skipped while acquiring locks on jobs. The cursor is optional, configured behind the run_at_cursor flag when starting a worker. If not specified the run_at clause will always be set to -infinity, performing the same as if it was not present.

BBrannick and others added 9 commits June 18, 2026 16:05
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…_to_lock

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove unused job_2 let binding in locker_spec.rb "with run_at_cursor enabled" context
- Update CLI description to clarify "due before" instead of "scheduled before"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…in/lock_job_query

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@BBrannick
BBrannick requested a review from a team June 22, 2026 14:09
@JoeSouthan

Copy link
Copy Markdown
Contributor

Do you have a query plan before and after for this?

@BBrannick

Copy link
Copy Markdown
Contributor Author

Do you have a query plan before and after for this?

I have query plans which include the index hinting we added, which shows lower index read execution when including the run_at cursor.
https://gist.github.com/BBrannick/4525e6a22a7708768cc46d4f559b122d

@stevetrinh

Copy link
Copy Markdown

I'm a bit confused. run_at_cursor is a boolean in one function and string timestamp in another. Should we rename them differently?

@BBrannick

Copy link
Copy Markdown
Contributor Author

I'm a bit confused. run_at_cursor is a boolean in one function and string timestamp in another. Should we rename them differently?

Fair point. It's a boolean when it's being passed to the worker (use or don't use the cursor), then its a timestamp when its the actual cursor value. I'll make the distinction clearer.

@stevetrinh stevetrinh 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.

:shipit:

@stevetrinh

Copy link
Copy Markdown

oh the specs 🫠

…stamp value

run_at_cursor is now only used as the boolean feature flag on Locker/Worker.
The actual timestamp lower bound passed through the locking methods is
renamed run_at_lower_bound to make the distinction clear.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread lib/que/locker.rb Outdated
# For more information, see the 'Predicate Specificity' chapter of:
# https://brandur.org/postgres-queues
class Locker
RUN_AT_CURSOR_RESET = "-infinity"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That is a bit confusing, not sure if nil and testing nil will be clearer, can leave it

@BBrannick
BBrannick merged commit 342d021 into master Jun 24, 2026
8 checks passed
@BBrannick
BBrannick deleted the run-at-cursor branch June 24, 2026 08:42
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.

5 participants