Module: Resque::StuckQueue
- Defined in:
- lib/resque_stuck_queue.rb,
lib/resque_stuck_queue/config.rb,
lib/resque_stuck_queue/signals.rb,
lib/resque_stuck_queue/version.rb,
lib/resque_stuck_queue/heartbeat_job.rb
Defined Under Namespace
Modules: Signals
Classes: Config, HeartbeatJob
Constant Summary
collapse
- HEARTBEAT_INTERVAL =
5 * 60
- WATCHER_INTERVAL =
send heartbeat job every 5 minutes
5
- TRIGGER_TIMEOUT =
check key is udpated every 5 seconds.
60 * 60
- TRIGGERED_HANDLER =
must be called by convention: type_handler
proc { |queue_name, lag| Resque::StuckQueue::LOGGER.info("Shit gone bad with them queues...on #{queue_name}. Lag time is #{lag}") }
- RECOVERED_HANDLER =
proc { |queue_name, lag| Resque::StuckQueue::LOGGER.info("recovered queue phew #{queue_name}. Lag time is #{lag}") }
- LOGGER =
Logger.new($stdout)
- HEARTBEAT_KEY =
"resque-stuck-queue"
- TRIGGERED_KEY =
"resque-stuck-queue-last-triggered"
- VERSION =
"0.4.3"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
19
20
21
|
# File 'lib/resque_stuck_queue.rb', line 19
def config
@config
end
|
Class Method Details
.abort_on_exception ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/resque_stuck_queue.rb', line 57
def abort_on_exception
if !config[:abort_on_exception].nil?
config[:abort_on_exception]
else
true
end
end
|
.force_stop! ⇒ Object
109
110
111
112
113
|
# File 'lib/resque_stuck_queue.rb', line 109
def force_stop!
logger.info("Force stopping")
@threads.map(&:kill)
reset!
end
|
.heartbeat_key_for(queue) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/resque_stuck_queue.rb', line 33
def heartbeat_key_for(queue)
if config[:heartbeat_key]
"#{queue}:#{config[:heartbeat_key]}"
else
"#{queue}:#{HEARTBEAT_KEY}"
end
end
|
.heartbeat_keys ⇒ Object
49
50
51
|
# File 'lib/resque_stuck_queue.rb', line 49
def heartbeat_keys
queues.map{|q| heartbeat_key_for(q) }
end
|
.logger ⇒ Object
25
26
27
|
# File 'lib/resque_stuck_queue.rb', line 25
def logger
@logger ||= (config[:logger] || StuckQueue::LOGGER)
end
|
.queues ⇒ Object
53
54
55
|
# File 'lib/resque_stuck_queue.rb', line 53
def queues
@queues ||= (config[:queues] || [:app])
end
|
.redis ⇒ Object
29
30
31
|
# File 'lib/resque_stuck_queue.rb', line 29
def redis
@redis ||= config[:redis]
end
|
.reset! ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/resque_stuck_queue.rb', line 115
def reset!
@config = Config.new
@queues = nil
@running = false
@logger = nil
end
|
.reset_keys ⇒ Object
123
124
125
126
127
128
|
# File 'lib/resque_stuck_queue.rb', line 123
def reset_keys
queues.each do |qn|
redis.del(heartbeat_key_for(qn))
redis.del(triggered_key_for(qn))
end
end
|
.start ⇒ Object
call this after setting config. once started you should’t be allowed to modify it
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/resque_stuck_queue.rb', line 73
def start
@running = true
@stopped = false
@threads = []
config.validate_required_keys!
config.freeze
Signals.enable!
log_starting_info
reset_keys
Redis::Classy.db = redis if Redis::Classy.db.nil?
pretty_process_name
setup_heartbeat_thread
setup_watcher_thread
@threads.map(&:join)
logger.info("threads stopped")
@stopped = true
end
|
.start_in_background ⇒ Object
65
66
67
68
69
70
|
# File 'lib/resque_stuck_queue.rb', line 65
def start_in_background
Thread.new do
Thread.current.abort_on_exception = abort_on_exception
self.start
end
end
|
.stop ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'lib/resque_stuck_queue.rb', line 100
def stop
reset!
while @stopped == false
sleep 1
end
logger.info("Stopped")
end
|
.stopped? ⇒ Boolean
130
131
132
|
# File 'lib/resque_stuck_queue.rb', line 130
def stopped?
@stopped
end
|
.triggered_key_for(queue) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/resque_stuck_queue.rb', line 41
def triggered_key_for(queue)
if config[:triggered_key]
"#{queue}:#{self.config[:triggered_key]}"
else
"#{queue}:#{TRIGGERED_KEY}"
end
end
|