class Resqutils::StaleWorkers
Vends stale workers that have been running “too long”
Public Class Methods
new(seconds_to_be_considered_stale = 3600)
click to toggle source
Create a StaleWorkers
instance.
- seconds_to_be_considered_stale
-
if present, this is the number of seconds a worker will have to have been running to be considered stale
# File lib/resqutils/stale_workers.rb, line 10 def initialize(seconds_to_be_considered_stale = 3600) @seconds_to_be_considered_stale = seconds_to_be_considered_stale_from_env! || seconds_to_be_considered_stale end
Public Instance Methods
each(&block)
click to toggle source
Yield all currently stale workers. The yielded objects are Resque's representation, which is not well documented, however you can reasonably assume it will respond to id, queue, and run_at
# File lib/resqutils/stale_workers.rb, line 16 def each(&block) if block.nil? stale_workers.to_enum else stale_workers.each(&block) end end
Private Instance Methods
seconds_to_be_considered_stale_from_env!()
click to toggle source
# File lib/resqutils/stale_workers.rb, line 34 def seconds_to_be_considered_stale_from_env! seconds_to_be_considered_stale = String(ENV["RESQUTILS_SECONDS_TO_BE_CONSIDERED_STALE"]) if seconds_to_be_considered_stale.strip.length == 0 nil elsif seconds_to_be_considered_stale.to_i == 0 raise "You set a stale value of 0 seconds, making all jobs stale; probably not what you want" else seconds_to_be_considered_stale.to_i end end
stale_workers()
click to toggle source
# File lib/resqutils/stale_workers.rb, line 26 def stale_workers Resque.workers.map(&self.method(:worker_with_start_time)).select(&:stale?).map(&:worker) end
worker_with_start_time(worker)
click to toggle source
# File lib/resqutils/stale_workers.rb, line 30 def worker_with_start_time(worker) WorkerWithStartTime.new(worker,@seconds_to_be_considered_stale) end