class Pallets::Scheduler
Public Class Methods
new(manager, backend)
click to toggle source
# File lib/pallets/scheduler.rb, line 3 def initialize(manager, backend) @manager = manager @backend = backend @needs_to_stop = false @thread = nil end
Public Instance Methods
debug()
click to toggle source
# File lib/pallets/scheduler.rb, line 25 def debug @thread.backtrace end
id()
click to toggle source
# File lib/pallets/scheduler.rb, line 29 def id "S#{@thread.object_id.to_s(36)}".upcase if @thread end
needs_to_stop?()
click to toggle source
# File lib/pallets/scheduler.rb, line 21 def needs_to_stop? @needs_to_stop end
shutdown()
click to toggle source
# File lib/pallets/scheduler.rb, line 14 def shutdown @needs_to_stop = true return unless @thread @thread.join end
start()
click to toggle source
# File lib/pallets/scheduler.rb, line 10 def start @thread ||= Thread.new { wait_initial_bit; work } end
Private Instance Methods
wait_a_bit(seconds = Pallets.configuration.scheduler_polling_interval)
click to toggle source
# File lib/pallets/scheduler.rb, line 50 def wait_a_bit(seconds = Pallets.configuration.scheduler_polling_interval) # Wait for roughly the configured number of seconds # We don't want to block the entire polling interval, since we want to # deal with shutdowns synchronously and as fast as possible seconds.times do break if needs_to_stop? sleep 1 end end
wait_initial_bit()
click to toggle source
# File lib/pallets/scheduler.rb, line 44 def wait_initial_bit # Randomly wait a bit before starting working, so that multiple processes # will not hit the backend all at once wait_a_bit(rand(Pallets.configuration.scheduler_polling_interval)) end
work()
click to toggle source
# File lib/pallets/scheduler.rb, line 35 def work loop do break if needs_to_stop? @backend.reschedule_all(Time.now.to_f) wait_a_bit end end