Class: Resqutils::StaleWorkers

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/resqutils/stale_workers.rb

Overview

Vends stale workers that have been running “too long”

Defined Under Namespace

Classes: WorkerWithStartTime

Instance Method Summary collapse

Constructor Details

#initialize(seconds_to_be_considered_stale = 3600) ⇒ StaleWorkers

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


10
11
12
# 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

Instance Method Details

#each(&block) ⇒ Object

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


16
17
18
19
20
21
22
# 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