Class: Sidekiq::Cron::Poller

Inherits:
Object
  • Object
show all
Includes:
Actor, Util
Defined in:
lib/sidekiq/cron/poller.rb

Overview

The Poller checks Redis every N seconds for sheduled cron jobs

Instance Method Summary collapse

Instance Method Details

#poll(first_time = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sidekiq/cron/poller.rb', line 17

def poll(first_time=false)
  watchdog('scheduling cron poller thread died!') do
    add_jitter if first_time

    begin
      time_now = Time.now

      #go through all jobs
      Sidekiq::Cron::Job.all.each do |job|
        #test if job should be enequed
        # if yes add job to queue
        begin
          job.test_and_enque_for_time! time_now if job && job.valid?
        rescue => ex
          #problem somewhere in one job
          logger.error "CRON JOB: #{ex.message}"
          logger.error "CRON JOB: #{ex.backtrace.first}"
        end
      end

    rescue => ex
      # Most likely a problem with redis networking.
      # Punt and try again at the next interval
      logger.error ex.message
      logger.error ex.backtrace.first
    end

    after(poll_interval) { poll }
  end
end