Skip to content

Commit

Permalink
fix(cron): Fixed cron jobs being consumed by multiple workers
Browse files Browse the repository at this point in the history
Because of how the consume cron query is built, it is possible for
multiple workers to attempt to consume the same cron job at the same
time. This tweaks the query such that only a single worker should be
able to consume the cron job now.
  • Loading branch information
elliotcourant committed Jul 5, 2024
1 parent 402fc2a commit 29b9a87
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion server/background/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ func (p *postgresJobProcessor) consumeCronMaybe(queue string, next time.Time) (*
subQuery := p.db.ModelContext(ctx, new(models.CronJob)).
Column("queue").
Where(`"queue" = ?`, queue).
Where(`"next_run_at" <= ?`, next).
Where(`"next_run_at" < ?`, next).
For(`UPDATE SKIP LOCKED`).
Limit(1)

Expand Down

0 comments on commit 29b9a87

Please sign in to comment.