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::PAUSE_TIME

Instance Method Summary collapse

Methods included from Util

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

Methods included from ExceptionHandler

#handle_exception

Constructor Details

#initializePoller

Returns a new instance of Poller.



74
75
76
77
78
79
80
# File 'lib/sidekiq/scheduled.rb', line 74

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

Instance Method Details

#enqueueObject



107
108
109
110
111
112
113
114
# File 'lib/sidekiq/scheduled.rb', line 107

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

#startObject



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/sidekiq/scheduled.rb', line 95

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

    until @done
      enqueue
      wait
    end
    Sidekiq.logger.info("Scheduler exiting...")
  }
end

#terminateObject

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



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sidekiq/scheduled.rb', line 83

def terminate
  @done = true
  @enq.terminate if @enq.respond_to?(:terminate)

  if @thread
    t = @thread
    @thread = nil
    @sleeper << 0
    t.value
  end
end