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

Improve sidekiq-cron patch #2387

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Unreleased

### Features

- Add support for $SENTRY_DEBUG and $SENTRY_SPOTLIGHT ([#2374](https://github.com/getsentry/sentry-ruby/pull/2374))
- Support human readable intervals in `sidekiq-cron` ([#2387](https://github.com/getsentry/sentry-ruby/pull/2387))

## 5.19.0

Expand Down
4 changes: 2 additions & 2 deletions sentry-sidekiq/lib/sentry/sidekiq/cron/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def save
unless klass_const.send(:ancestors).include?(Sentry::Cron::MonitorCheckIns)
klass_const.send(:include, Sentry::Cron::MonitorCheckIns)
klass_const.send(:sentry_monitor_check_ins,
slug: name,
monitor_config: Sentry::Cron::MonitorConfig.from_crontab(cron))
slug: name.to_s,
monitor_config: Sentry::Cron::MonitorConfig.from_crontab(parsed_cron.original))
end

true
Expand Down
4 changes: 4 additions & 0 deletions sentry-sidekiq/spec/fixtures/sidekiq-cron-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ manual:
cron: "* * * * *"
class: "SadWorkerWithCron"

human_readable_cron:
cron: "every 5 minutes"
class: HappyWorkerWithHumanReadableCron

invalid_cron:
cron: "not a crontab"
class: "ReportingWorker"
18 changes: 18 additions & 0 deletions sentry-sidekiq/spec/sentry/sidekiq/cron/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
before do
schedule_file = 'spec/fixtures/sidekiq-cron-schedule.yml'
schedule = Sidekiq::Cron::Support.load_yaml(ERB.new(IO.read(schedule_file)).result)
schedule = schedule.merge(symbol_name: { cron: '* * * * *', class: HappyWorkerWithSymbolName })
# sidekiq-cron 2.0+ accepts second argument to `load_from_hash!` with options,
# such as {source: 'schedule'}, but sidekiq-cron 1.9.1 (last version to support Ruby 2.6) does not.
# Since we're not using the source option in our code anyway, it's safe to not pass the 2nd arg.
Expand Down Expand Up @@ -48,6 +49,23 @@
expect(HappyWorkerForCron.sentry_monitor_config.schedule.value).to eq('* * * * *')
end

it 'patches HappyWorkerWithHumanReadableCron' do
expect(HappyWorkerWithHumanReadableCron.ancestors).to include(Sentry::Cron::MonitorCheckIns)
expect(HappyWorkerWithHumanReadableCron.sentry_monitor_slug).to eq('human_readable_cron')
expect(HappyWorkerWithHumanReadableCron.sentry_monitor_config).to be_a(Sentry::Cron::MonitorConfig)
expect(HappyWorkerWithHumanReadableCron.sentry_monitor_config.schedule).to be_a(Sentry::Cron::MonitorSchedule::Crontab)
expect(HappyWorkerWithHumanReadableCron.sentry_monitor_config.schedule.value).to eq('*/5 * * * *')
end

it 'patches HappyWorkerWithSymbolName' do
expect(HappyWorkerWithSymbolName.ancestors).to include(Sentry::Cron::MonitorCheckIns)
expect(HappyWorkerWithSymbolName.sentry_monitor_slug).to eq('symbol_name')
expect(HappyWorkerWithSymbolName.sentry_monitor_config).to be_a(Sentry::Cron::MonitorConfig)
expect(HappyWorkerWithSymbolName.sentry_monitor_config.schedule).to be_a(Sentry::Cron::MonitorSchedule::Crontab)
expect(HappyWorkerWithSymbolName.sentry_monitor_config.schedule.value).to eq('* * * * *')
end


it 'does not override SadWorkerWithCron manually set values' do
expect(SadWorkerWithCron.ancestors).to include(Sentry::Cron::MonitorCheckIns)
expect(SadWorkerWithCron.sentry_monitor_slug).to eq('failed_job')
Expand Down
2 changes: 2 additions & 0 deletions sentry-sidekiq/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class HappyWorkerForCron < HappyWorker; end
class HappyWorkerForScheduler < HappyWorker; end
class HappyWorkerForSchedulerWithTimezone < HappyWorker; end
class EveryHappyWorker < HappyWorker; end
class HappyWorkerWithHumanReadableCron < HappyWorker; end
class HappyWorkerWithSymbolName < HappyWorker; end

class HappyWorkerWithCron < HappyWorker
include Sentry::Cron::MonitorCheckIns
Expand Down
Loading