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.7"
Class Attribute Summary collapse
-
.config ⇒ Object
how often we refresh the key :heartbeat = 5 * 60.
Class Method Summary collapse
- .force_stop! ⇒ Object
- .global_key ⇒ Object
- .logger ⇒ Object
- .reset! ⇒ Object
-
.start ⇒ Object
call this after setting config.
- .start_in_background ⇒ Object
- .stop ⇒ 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
81 82 83 84 85 |
# File 'lib/resque_stuck_queue.rb', line 81 def force_stop! logger.info("Force stopping") @threads.map(&:kill) reset! end |
.global_key ⇒ Object
98 99 100 101 |
# File 'lib/resque_stuck_queue.rb', line 98 def global_key # public, for use in custom heartbeat job config[:global_key] || GLOBAL_KEY 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
87 88 89 90 91 92 |
# File 'lib/resque_stuck_queue.rb', line 87 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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/resque_stuck_queue.rb', line 55 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
72 73 74 75 76 77 78 79 |
# File 'lib/resque_stuck_queue.rb', line 72 def stop reset! # wait for clean thread shutdown while @stopped == false sleep 1 end logger.info("Stopped") end |
.stopped? ⇒ Boolean
94 95 96 |
# File 'lib/resque_stuck_queue.rb', line 94 def stopped? @stopped end |