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

(fix) crons: require sidekiq-cron early #2173

Merged
merged 2 commits into from
Nov 23, 2023
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
8 changes: 7 additions & 1 deletion sentry-sidekiq/lib/sentry/sidekiq/cron/job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# frozen_string_literal: true

return unless defined?(::Sidekiq::Cron::Job)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, but perhaps it's worth keeping the defined? check in case sidekiq-cron decides to change their API? Would be good to fail gracefully instead of erroring out.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case they'll need to rename the constant in a way that doesn't fit the convention anymore, which I think is relatively unlikely. And if that do happen, which will be a breaking change to us, we probably don't want it to always fail silently? 🤔

# Try requiring sidekiq-cron to ensure it's loaded before the integration.
# If sidekiq-cron is not available, do nothing.
begin
require "sidekiq-cron"
rescue LoadError
return

Check warning on line 8 in sentry-sidekiq/lib/sentry/sidekiq/cron/job.rb

View check run for this annotation

Codecov / codecov/patch

sentry-sidekiq/lib/sentry/sidekiq/cron/job.rb#L8

Added line #L8 was not covered by tests
end

module Sentry
module Sidekiq
Expand Down
5 changes: 4 additions & 1 deletion sentry-sidekiq/spec/sentry/sidekiq/cron/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
before do
schedule_file = 'spec/fixtures/schedule.yml'
schedule = Sidekiq::Cron::Support.load_yaml(ERB.new(IO.read(schedule_file)).result)
Sidekiq::Cron::Job.load_from_hash!(schedule, source: 'schedule')
# 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.
Sidekiq::Cron::Job.load_from_hash!(schedule)
end

it 'patches class' do
Expand Down
Loading