bensheldon / good_job

Multithreaded, Postgres-based, Active Job backend for Ruby on Rails.
https://goodjob-demo.herokuapp.com/
MIT License
2.69k stars 200 forks source link

Unique constraint violation messages in postgres error logs #1536

Open betmenslido opened 6 days ago

betmenslido commented 6 days ago

Hello and thanks for your great work!

We are using latest GJ (multiple workers) and Googles cloudSQL postgres with it, and we got steady stream of unique constraint violation errors:

log: cloudsql.googleapis.com/postgres.log error: duplicate key value violates unique constraint "index_good_jobs_on_cron_key_and_cron_at_cond"

We get around 15 of those every 10 minutes. Nothing seems out of order when looking at GJ logs.

Would like to confirm that this is by design and nothing to worry about. Thank you!

Earlopain commented 6 days ago

Hi! This is expected. Here is a previous issue about this: https://github.com/bensheldon/good_job/issues/1230

good_job relies on database constraints to ensure that cron jobs are only executed once. When you have multiple workers running, they will all attempt to enqueue the cron job. Only one will succeed, the others will fail because of the constraints. good_job rescues the exception from ActiveRecord but postgres will log it regardless.

Hope that makes sense. This is also briefly documented here: https://github.com/bensheldon/good_job?tab=readme-ov-file#cron-style-repeatingrecurring-jobs

We can keep this issue open to better document this in the readme.