Module: ResquePauseHelper
- Defined in:
- lib/resque_pause_helper.rb
Constant Summary collapse
- DEFAULT_GLOBAL_PAUSE_KEY =
"pause:all"
Class Method Summary collapse
- .check_paused(args) ⇒ Object
-
.encode(object) ⇒ Object
Given a Ruby object, returns a string suitable for storage in a queue.
- .enqueue_job(args) ⇒ Object
- .global_pause ⇒ Object
- .global_pause_key ⇒ Object
- .global_pause_key=(key) ⇒ Object
- .global_paused? ⇒ Boolean
- .global_unpause ⇒ Object
- .pause(queue) ⇒ Object
- .paused?(queue) ⇒ Boolean
- .unpause(queue) ⇒ Object
Class Method Details
.check_paused(args) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/resque_pause_helper.rb', line 43 def check_paused(args) if ResquePauseHelper.paused?(args[:queue]) enqueue_job(args) raise Resque::Job::DontPerform.new "Queue #{args[:queue]} is paused!" end end |
.encode(object) ⇒ Object
Given a Ruby object, returns a string suitable for storage in a queue.
51 52 53 54 55 56 57 |
# File 'lib/resque_pause_helper.rb', line 51 def encode(object) if MultiJson.respond_to?(:dump) && MultiJson.respond_to?(:load) MultiJson.dump object else MultiJson.encode object end end |
.enqueue_job(args) ⇒ Object
39 40 41 |
# File 'lib/resque_pause_helper.rb', line 39 def enqueue_job(args) Resque.redis.lpush("queue:#{args[:queue]}", ResquePauseHelper.encode(:class => args[:class].to_s, :args => args[:args])) end |
.global_pause ⇒ Object
27 28 29 |
# File 'lib/resque_pause_helper.rb', line 27 def global_pause() Resque.redis.set global_pause_key, true end |
.global_pause_key ⇒ Object
63 64 65 |
# File 'lib/resque_pause_helper.rb', line 63 def global_pause_key @global_pause_key ||= DEFAULT_GLOBAL_PAUSE_KEY end |
.global_pause_key=(key) ⇒ Object
59 60 61 |
# File 'lib/resque_pause_helper.rb', line 59 def global_pause_key=(key) @global_pause_key = key end |
.global_paused? ⇒ Boolean
35 36 37 |
# File 'lib/resque_pause_helper.rb', line 35 def global_paused?() !!Resque.redis.get(global_pause_key) end |
.global_unpause ⇒ Object
31 32 33 |
# File 'lib/resque_pause_helper.rb', line 31 def global_unpause() Resque.redis.del global_pause_key end |
.pause(queue) ⇒ Object
19 20 21 |
# File 'lib/resque_pause_helper.rb', line 19 def pause(queue) Resque.redis.set "pause:queue:#{queue}", true end |
.paused?(queue) ⇒ Boolean
15 16 17 |
# File 'lib/resque_pause_helper.rb', line 15 def paused?(queue) !Resque.redis.mget("pause:queue:#{queue}", global_pause_key).all?(&:nil?) end |
.unpause(queue) ⇒ Object
23 24 25 |
# File 'lib/resque_pause_helper.rb', line 23 def unpause(queue) Resque.redis.del "pause:queue:#{queue}" end |