Module: Resque::Plugins::Status::ClassOverridesAndExtensions
- Defined in:
- lib/resque_manager/overrides/resque_status/status.rb
Instance Method Summary collapse
- #counter(counter, uuid) ⇒ Object
-
#counter_key(counter, uuid) ⇒ Object
If multiple workers are running at once and you need an incrementer, you can’t use the status’ num attribute because of race conditions.
-
#enqueue_to(queue, klass, options = {}) ⇒ Object
OVERRIDE to set the name that will be displayed on the status page for this job when it is first queued.
- #incr_counter(counter, uuid) ⇒ Object
-
#perform(uuid = nil, options = {}) ⇒ Object
This is the method called by Resque::Worker when processing jobs.
-
#remove(uuid) ⇒ Object
OVERRIDE to clear all the keys that have the UUI.
Instance Method Details
#counter(counter, uuid) ⇒ Object
60 61 62 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 60 def counter(counter, uuid) Resque.redis[counter_key(counter, uuid)].to_i end |
#counter_key(counter, uuid) ⇒ Object
If multiple workers are running at once and you need an incrementer, you can’t use the status’ num attribute because of race conditions. You can use a counter and call incr on it instead
56 57 58 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 56 def counter_key(counter, uuid) "#{counter}:#{uuid}" end |
#enqueue_to(queue, klass, options = {}) ⇒ Object
OVERRIDE to set the name that will be displayed on the status page for this job when it is first queued. The name will be changed when set_status is called, which is called on #tick, to the value set in your name method, but the UI name field is blank when it is first queued, so setting it here so we have something.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 20 def enqueue_to(queue, klass, = {}) uuid = Resque::Plugins::Status::Hash.generate_uuid Resque::Plugins::Status::Hash.create uuid, {name: "#{self.name}: #{options.inspect}"}.merge() if Resque.enqueue_to(queue, klass, uuid, ) uuid else Resque::Plugins::Status::Hash.remove(uuid) nil end end |
#incr_counter(counter, uuid) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 64 def incr_counter(counter, uuid) key = counter_key(counter, uuid) n = Resque.redis.incr(key) if Resque::Plugins::Status::Hash.expire_in Resque.redis.expire(key, Resque::Plugins::Status::Hash.expire_in) end n end |
#perform(uuid = nil, options = {}) ⇒ Object
This is the method called by Resque::Worker when processing jobs. It creates a new instance of the job class and populates it with the uuid and options.
You should not override this method, rather the perform instance method. OVERRIDE to get the worker and set when initializing the class
38 39 40 41 42 43 44 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 38 def perform(uuid=nil, = {}) uuid ||= Resque::Plugins::Status::Hash.generate_uuid worker = yield if block_given? instance = new(uuid, worker, ) instance.safe_perform! instance end |
#remove(uuid) ⇒ Object
OVERRIDE to clear all the keys that have the UUI. status, counters, etc.
47 48 49 50 51 52 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 47 def remove(uuid) Resque.redis.zrem(Resque::Plugins::Status::Hash.set_key, uuid) Resque.redis.keys("*#{uuid}").each do |key| Resque.redis.del(key) end end |