Skip to content

Commit

Permalink
Fix poller affecting Sidekiq scheduled set poller (#359)
Browse files Browse the repository at this point in the history
Avoid setting global config so that we do not change the behavior of the
Sidekiq scheduled set poller.

Closes #358
  • Loading branch information
engwan authored Sep 16, 2022
1 parent 1f9cc7d commit 7acecde
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/sidekiq/cron/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Launcher

# Add cron poller and execute normal initialize of Sidekiq launcher.
def initialize(options)
@cron_poller = Sidekiq::Cron::Poller.new
@cron_poller = Sidekiq::Cron::Poller.new(options)
super(options)
end

Expand Down
19 changes: 10 additions & 9 deletions lib/sidekiq/cron/poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@

module Sidekiq
module Cron
POLL_INTERVAL = Sidekiq::Options[:average_scheduled_poll_interval] || 30
POLL_INTERVAL = 30

# The Poller checks Redis every N seconds for sheduled cron jobs.
class Poller < Sidekiq::Scheduled::Poller
def initialize
Sidekiq.configure_server do
Sidekiq::Options[:poll_interval_average] = POLL_INTERVAL
end

def initialize(options = {})
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('6.5.0')
# Sidekiq Poller init requires a config argument.
super(Sidekiq)
else
super
else
# Old version of Sidekiq does not accept a config argument.
@config = options
super()
end
end

Expand All @@ -45,6 +42,10 @@ def enqueue_job(job, time = Time.now.utc)
Sidekiq.logger.error "CRON JOB: #{ex.backtrace.first}"
handle_exception(ex) if respond_to?(:handle_exception)
end

def poll_interval_average
@config[:average_scheduled_poll_interval] || POLL_INTERVAL
end
end
end
end

0 comments on commit 7acecde

Please sign in to comment.