Skip to content

feat(crons): Add GoodJob cron monitoring - #3147

Draft
wedamija wants to merge 1 commit into
danf/cron-fugit-configfrom
danf/good-job-crons
Draft

wedamija wants to merge 1 commit into
danf/cron-fugit-configfrom
danf/good-job-crons

Conversation

@wedamija

Copy link
Copy Markdown
Member

Part of a series adding automatic Crons monitoring for the most-used job schedulers in each SDK. Check-ins for a monitor that doesn't exist yet are dropped, so today each monitor has to be created by hand with its schedule copied from the code. Sending the job's schedule as the monitor config lets Sentry create the monitor and keep it in sync.

This adds an opt-in patch to sentry-rails for GoodJob cron entries (config.good_job.cron):

config.enabled_patches << :good_job_cron
config.rails.good_job_exclude_cron_jobs = ["clear_cache", /^tmp_/]

Entries in good_job_exclude_cron_jobs are skipped; strings and symbols match the cron key, regexps are matched against it.

Each run sends in-progress and ok/error check-ins, with the cron key as the slug and the entry's schedule as the monitor config.

  • The slug comes from the cron key, not the job class, so one class behind several entries gets one monitor per entry.
  • When GoodJob enqueues a cron entry, the slug and schedule go into the job payload. The worker sends the check-ins from an around_perform, so retries check in too. Same approach as the Solid Queue patch in feat(crons): Add Solid Queue recurring task monitoring #3140.
  • The schedule is read where GoodJob evaluates it, so the time zone matches: the zone in the cron line, then Time.zone.
  • Schedules that can't be expressed in the Crons schedule format (for example, a job that runs every 10 seconds) and entries whose cron is a proc check in without a config.
  • Jobs that already call sentry_monitor_check_ins are left alone.

Builds on the community PR #2751 by @amkisko, which proposed a sentry-good_job integration. This version lives in sentry-rails next to the Solid Queue patch and reuses Sentry::Cron::FugitSchedule.

Stacked on #3141. The lockfile changes only add good_job as a dev dependency for the spec (Rails 6.1+, Ruby 3.0+).

Sends check-ins for GoodJob cron entries when the :good_job_cron patch
is enabled, using the cron key as the slug and the entry's schedule as
the monitor config. Keys can be skipped with
config.rails.good_job_exclude_cron_jobs.

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant