Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periodic job enqueuer: Set scheduled_at according to expected next run time #341

Merged

Conversation

brandur
Copy link
Contributor

@brandur brandur commented May 7, 2024

Currently, a periodic job that's inserted gets a value in scheduled_at
that defaults to the database's now(). Here, we alter this with a
minor nicety requested in #340 wherein we set scheduled_at to the
precise time we expected a periodic job to be scheduled. This value is
will be very close to now(), but likely a little sooner because
there's some lag in the insert loop between when job insert params are
generated and when the insert happens.

Jobs are inserted with state available (rather than scheduled), so
this should have very little functional effect. In a busy system it may
cause the periodic jobs to be favored slightly because when locking
available jobs, scheduled_at is one of the fields we order on for
priority.

@brandur brandur force-pushed the brandur-schedule-periodic-jobs-according-to-next-run-at branch from 325d349 to 338bc7d Compare May 7, 2024 05:19
@brandur brandur force-pushed the brandur-schedule-periodic-jobs-according-to-next-run-at branch from 338bc7d to 6a27ea0 Compare May 7, 2024 05:22
@brandur brandur requested a review from bgentry May 7, 2024 05:24
@dhermes
Copy link
Contributor

dhermes commented May 7, 2024

Awesome stuff, thank you!

@brandur brandur force-pushed the brandur-schedule-periodic-jobs-according-to-next-run-at branch from 6a27ea0 to 14dcd5d Compare May 8, 2024 05:09
@brandur
Copy link
Contributor Author

brandur commented May 8, 2024

Thanks guys. I unset this as resolving #340 since there's still a little discussion going over there.

…run time

Currently, a periodic job that's inserted gets a value in `scheduled_at`
that defaults to the database's `now()`. Here, we alter this with a
minor nicety requested in #340 wherein we set `scheduled_at` to the
precise time we expected a periodic job to be scheduled. This value is
will be very close to `now()`, but likely a little sooner because
there's some lag in the insert loop between when job insert params are
generated and when the insert happens.

Jobs are inserted with state `available` (rather than `scheduled`), so
this should have very little functional effect. In a busy system it may
cause the periodic jobs to be favored slightly because when locking
available jobs, `scheduled_at` is one of the fields we order on for
priority.
@brandur brandur force-pushed the brandur-schedule-periodic-jobs-according-to-next-run-at branch from 14dcd5d to e5d8638 Compare May 8, 2024 05:10
@brandur brandur merged commit 23d0b8f into master May 8, 2024
10 checks passed
@brandur brandur deleted the brandur-schedule-periodic-jobs-according-to-next-run-at branch May 8, 2024 05:28
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.

3 participants