Module: Resque::StuckQueue

Defined in:
lib/resque_stuck_queue.rb,
lib/resque_stuck_queue/version.rb

Constant Summary collapse

GLOBAL_KEY =
"resque-stuck-queue"
VERIFIED_KEY =
"resque-stuck-queue-ran-once"
HEARTBEAT =

check/refresh every hour

60 * 60
TRIGGER_TIMEOUT =

warn/trigger 5 hours

5 * 60 * 60
HANDLER =
proc { $stderr.puts("Shit gone bad with them queues.") }
VERSION =
"0.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.config ⇒ Object

how often we refresh the key

:heartbeat = 5 * 60

this could just be :heartbeat but it's possible there's an acceptable lag/bottleneck

in the queue that we want to allow to be before we think it's bad.

:trigger_timeout = 10 * 60

The global key that will be used to check the latest time

:global_key = "resque-stuck-queue"

for threads involved here. default is false

:abort_on_exception

default handler

config = proc { send_mail }



34
35
36
# File 'lib/resque_stuck_queue.rb', line 34

def config
  @config
end

Class Method Details

.force_stop! ⇒ Object



81
82
83
# File 'lib/resque_stuck_queue.rb', line 81

def force_stop!
  @threads.map(&:kill)
end

.start ⇒ Object

call this after setting config. once started you should't be allowed to modify it



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/resque_stuck_queue.rb', line 51

def start
  @running = true
  @stopped = false
  @threads = []
  config.freeze

  mark_first_use

  Thread.abort_on_exception = config[:abort_on_exception]

  enqueue_repeating_refresh_job
  setup_checker_thread

  # fo-eva.
  @threads.map(&:join)

  @stopped = true
end

.start_in_background ⇒ Object



38
39
40
41
42
# File 'lib/resque_stuck_queue.rb', line 38

def start_in_background
  Thread.new do
    self.start
  end
end

.stop ⇒ Object

for tests



71
72
73
74
75
76
77
78
79
# File 'lib/resque_stuck_queue.rb', line 71

def stop
  @config = config.dup #unfreeze
  @running = false

  # wait for clean thread shutdown
  while @stopped == false
    sleep 1
  end
end

.stop_in_background ⇒ Object



44
45
46
47
48
# File 'lib/resque_stuck_queue.rb', line 44

def stop_in_background
  Thread.new do
    self.start
  end
end