Class: Resque::Status
- Inherits:
-
Object
- Object
- Resque::Status
- Defined in:
- lib/resque_ui/overrides/resque_status/status.rb
Class Method Summary collapse
-
.clear(range_start = nil, range_end = nil) ⇒ Object
clear statuses from redis passing an optional range.
- .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.
- .incr_counter(counter, uuid) ⇒ Object
-
.status_ids(range_start = nil, range_end = nil) ⇒ Object
Return the
num
most recent status/job UUIDs in reverse chronological order.
Instance Method Summary collapse
-
#paused? ⇒ Boolean
The STATUSES constant is frozen, so we’ll just manually add the paused? method here.
Class Method Details
.clear(range_start = nil, range_end = nil) ⇒ Object
clear statuses from redis passing an optional range. See ‘statuses` for info about ranges
30 31 32 33 34 35 36 37 |
# File 'lib/resque_ui/overrides/resque_status/status.rb', line 30 def self.clear(range_start = nil, range_end = nil) status_ids(range_start, range_end).each do |id| redis.zrem(set_key, id) Resque.redis.keys("*#{id}").each do |key| Resque.redis.del(key) end end end |
.counter(counter, uuid) ⇒ Object
45 46 47 |
# File 'lib/resque_ui/overrides/resque_status/status.rb', line 45 def self.counter(counter, uuid) 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
41 42 43 |
# File 'lib/resque_ui/overrides/resque_status/status.rb', line 41 def self.counter_key(counter, uuid) "#{counter}:#{uuid}" end |
.incr_counter(counter, uuid) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/resque_ui/overrides/resque_status/status.rb', line 49 def self.incr_counter(counter, uuid) key = counter_key(counter, uuid) n = redis.incr(key) if expire_in redis.expire(key, expire_in) end n end |
.status_ids(range_start = nil, range_end = nil) ⇒ Object
Return the num
most recent status/job UUIDs in reverse chronological order. override the gem to fix the ordering
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/resque_ui/overrides/resque_status/status.rb', line 10 def self.status_ids(range_start = nil, range_end = nil) unless range_end && range_start # Because we want a reverse chronological order, we need to get a range starting # by the higest negative number. redis.zrevrange(set_key, 0, -1) || [] else # Because we want a reverse chronological order, we need to get a range starting # by the higest negative number. The ordering is transparent from the API user's # perspective so we need to convert the passed params if range_start == 0 range_start = -1 else range_start += 1 end (redis.zrange(set_key, -(range_end.abs), -(range_start.abs)) || []).reverse end end |
Instance Method Details
#paused? ⇒ Boolean
The STATUSES constant is frozen, so we’ll just manually add the paused? method here
4 5 6 |
# File 'lib/resque_ui/overrides/resque_status/status.rb', line 4 def paused? self['status'] === 'paused' end |