Class: Sidekiq::Scheduled::Poller

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/sidekiq/scheduled.rb

Overview

The Poller checks Redis every N seconds for jobs in the retry or scheduled set have passed their timestamp and should be enqueued. If so, it just pops the job back onto its original queue so the workers can pick it up like any other job.

Constant Summary collapse

INITIAL_WAIT =
10

Constants included from Util

Util::EXPIRY

Instance Method Summary collapse

Methods included from Util

#fire_event, #hostname, #identity, #logger, #process_nonce, #redis, #safe_thread, #watchdog

Methods included from ExceptionHandler

#handle_exception

Constructor Details

#initializePoller

Returns a new instance of Poller.



45
46
47
48
49
50
# File 'lib/sidekiq/scheduled.rb', line 45

def initialize
  @enq = (Sidekiq.options[:scheduled_enq] || Sidekiq::Scheduled::Enq).new
  @sleeper = ConnectionPool::TimedStack.new
  @done = false
  @thread = nil
end

Instance Method Details

#enqueueObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/sidekiq/scheduled.rb', line 75

def enqueue
  begin
    @enq.enqueue_jobs
  rescue => ex
    # Most likely a problem with redis networking.
    # Punt and try again at the next interval
    logger.error ex.message
    ex.backtrace.each do |bt|
      logger.error(bt)
    end
  end
end

#startObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sidekiq/scheduled.rb', line 63

def start
  @thread ||= safe_thread("scheduler") do
    initial_wait

    while !@done
      enqueue
      wait
    end
    Sidekiq.logger.info("Scheduler exiting...")
  end
end

#terminateObject

Shut down this instance, will pause until the thread is dead.



53
54
55
56
57
58
59
60
61
# File 'lib/sidekiq/scheduled.rb', line 53

def terminate
  @done = true
  if @thread
    t = @thread
    @thread = nil
    @sleeper << 0
    t.value
  end
end