Module: Resque::StuckQueue
- Defined in:
- lib/resque_stuck_queue.rb,
lib/resque_stuck_queue/version.rb
Constant Summary collapse
- GLOBAL_KEY =
"resque-stuck-queue"- HEARTBEAT =
check/refresh every hour
60 * 60
- TRIGGER_TIMEOUT =
warn/trigger 5 hours
5 * 60 * 60
- HANDLER =
proc { $stdout.puts("Shit gone bad with them queues.") }
- VERSION =
"0.0.4"
Class Attribute Summary collapse
-
.config ⇒ Object
how often we refresh the key :heartbeat = 5 * 60.
Class Method Summary collapse
- .force_stop! ⇒ Object
- .logger ⇒ Object
- .reset! ⇒ Object
-
.start ⇒ Object
call this after setting config.
- .start_in_background ⇒ Object
- .stop ⇒ Object
- .stop_in_background ⇒ Object
- .stopped? ⇒ Boolean
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 }
39 40 41 |
# File 'lib/resque_stuck_queue.rb', line 39 def config @config end |
Class Method Details
.force_stop! ⇒ Object
88 89 90 91 92 |
# File 'lib/resque_stuck_queue.rb', line 88 def force_stop! logger.info("Force stopping") @threads.map(&:kill) reset! end |
.logger ⇒ Object
43 44 45 |
# File 'lib/resque_stuck_queue.rb', line 43 def logger @logger ||= (config[:logger] || Logger.new($stdout)) end |
.reset! ⇒ Object
94 95 96 97 98 99 |
# File 'lib/resque_stuck_queue.rb', line 94 def reset! # clean state so we can stop and start in the same process. @config = config.dup #unfreeze @running = false @logger = nil end |
.start ⇒ Object
call this after setting config. once started you should't be allowed to modify it
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/resque_stuck_queue.rb', line 62 def start @running = true @stopped = false @threads = [] config.freeze enqueue_repeating_refresh_job setup_checker_thread # fo-eva. @threads.map(&:join) logger.info("threads stopped") @stopped = true end |
.start_in_background ⇒ Object
47 48 49 50 51 52 |
# File 'lib/resque_stuck_queue.rb', line 47 def start_in_background Thread.new do Thread.current.abort_on_exception = config[:abort_on_exception] self.start end end |
.stop ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/resque_stuck_queue.rb', line 79 def stop reset! # wait for clean thread shutdown while @stopped == false sleep 1 end logger.info("Stopped") end |
.stop_in_background ⇒ Object
54 55 56 57 58 59 |
# File 'lib/resque_stuck_queue.rb', line 54 def stop_in_background Thread.new do Thread.current.abort_on_exception = config[:abort_on_exception] self.start end end |
.stopped? ⇒ Boolean
101 102 103 |
# File 'lib/resque_stuck_queue.rb', line 101 def stopped? @stopped end |