riverqueue / river

Fast and reliable background jobs in Go
https://riverqueue.com
Mozilla Public License 2.0
3.22k stars 86 forks source link

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

Closed brandur closed 3 months ago

brandur commented 3 months ago

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.

dhermes commented 3 months ago

Awesome stuff, thank you!

brandur commented 3 months ago

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