Class: Resque::Plugins::Loner::Helpers
- Inherits:
-
Object
- Object
- Resque::Plugins::Loner::Helpers
- Extended by:
- Helpers
- Defined in:
- lib/resque-loner/helpers.rb
Class Method Summary collapse
- .cleanup_loners(queue) ⇒ Object
- .item_is_a_unique_job?(item) ⇒ Boolean
- .job_destroy(queue, klass, *args) ⇒ Object
- .loner_queued?(queue, item) ⇒ Boolean
- .mark_loner_as_queued(queue, item) ⇒ Object
- .mark_loner_as_unqueued(queue, job) ⇒ Object
- .unique_job_queue_key(queue, item) ⇒ Object
Class Method Details
.cleanup_loners(queue) ⇒ Object
53 54 55 56 |
# File 'lib/resque-loner/helpers.rb', line 53 def self.cleanup_loners(queue) keys = redis.keys("loners:queue:#{queue}:job:*") redis.del(*keys) unless keys.empty? end |
.item_is_a_unique_job?(item) ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/resque-loner/helpers.rb', line 28 def self.item_is_a_unique_job?(item) begin klass = constantize(item[:class] || item["class"]) klass.included_modules.include?(::Resque::Plugins::UniqueJob) rescue false # Resque testsuite also submits strings as job classes while Resque.enqueue'ing, end # so resque-loner should not start throwing up when that happens. end |
.job_destroy(queue, klass, *args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/resque-loner/helpers.rb', line 37 def self.job_destroy(queue, klass, *args) klass = klass.to_s redis_queue = "queue:#{queue}" redis.lrange(redis_queue, 0, -1).each do |string| json = decode(string) match = json['class'] == klass match &= json['args'] == args unless args.empty? if match Resque::Plugins::Loner::Helpers.mark_loner_as_unqueued( queue, json ) end end end |
.loner_queued?(queue, item) ⇒ Boolean
7 8 9 10 |
# File 'lib/resque-loner/helpers.rb', line 7 def self.loner_queued?(queue, item) return false unless item_is_a_unique_job?(item) redis.get(unique_job_queue_key(queue, item)) == "1" end |
.mark_loner_as_queued(queue, item) ⇒ Object
12 13 14 15 |
# File 'lib/resque-loner/helpers.rb', line 12 def self.mark_loner_as_queued(queue, item) return unless item_is_a_unique_job?(item) redis.set(unique_job_queue_key(queue, item), 1) end |
.mark_loner_as_unqueued(queue, job) ⇒ Object
17 18 19 20 21 |
# File 'lib/resque-loner/helpers.rb', line 17 def self.mark_loner_as_unqueued(queue, job) item = job.is_a?(Resque::Job) ? job.payload : job return unless item_is_a_unique_job?(item) redis.del(unique_job_queue_key(queue, item)) end |
.unique_job_queue_key(queue, item) ⇒ Object
23 24 25 26 |
# File 'lib/resque-loner/helpers.rb', line 23 def self.unique_job_queue_key(queue, item) job_key = constantize(item[:class] || item["class"]).redis_key(item) "loners:queue:#{queue}:job:#{job_key}" end |