Skip to content

Commit

Permalink
(fix) crons: require sidekiq-cron early (#2173)
Browse files Browse the repository at this point in the history
  • Loading branch information
natikgadzhi authored Nov 23, 2023
1 parent 16ef3e7 commit bc3de42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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)
# 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
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

0 comments on commit bc3de42

Please sign in to comment.