Class: Sidekiq::Cron::Poller

Inherits:
Scheduled::Poller
  • Object
show all
Defined in:
lib/sidekiq/cron/poller.rb

Overview

The Poller checks Redis every N seconds for sheduled cron jobs

Instance Method Summary collapse

Constructor Details

#initializePoller

Returns a new instance of Poller.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sidekiq/cron/poller.rb', line 11

def initialize
  Sidekiq.configure_server do |config|
    if config.respond_to?(:[])
      config[:poll_interval_average] = config[:average_scheduled_poll_interval] || POLL_INTERVAL
    else
      config.options[:poll_interval_average] = config.options[:average_scheduled_poll_interval] || POLL_INTERVAL
    end
  end

  if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("6.5.0")
    # Sidekiq Poller init requires a config argument
    super(Sidekiq)
  else
    super
  end
end

Instance Method Details

#enqueueObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sidekiq/cron/poller.rb', line 28

def enqueue
  time = Time.now.utc
  Sidekiq::Cron::Job.all.each do |job|
    enqueue_job(job, time)
  end
rescue => ex
  # Most likely a problem with redis networking.
  # Punt and try again at the next interval
  Sidekiq.logger.error ex.message
  Sidekiq.logger.error ex.backtrace.first
  handle_exception(ex) if respond_to?(:handle_exception)
end