Sha256: a6cefe1809501bf3df3c96556faad08de19d31199a08a9556f3e938727cd51da
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
# # Since there were not enough hooks to hook into, I have to overwrite # 3 methods of Resque::Job - the rest of the implementation is in the # proper Plugin namespace. # module Resque class Job # # Overwriting original create method to mark an item as queued # after Resque::Job.create has called Resque.push # def self.create_with_loner(queue, klass, *args) item = { :class => klass.to_s, :args => args } return "EXISTED" if Resque::Plugins::Loner::Helpers.loner_queued?(queue, item) job = create_without_loner(queue, klass, *args) Resque::Plugins::Loner::Helpers.mark_loner_as_queued(queue, item) job end # # Overwriting original reserve method to mark an item as unqueued # def self.reserve_with_loner(queue) item = reserve_without_loner(queue) Resque::Plugins::Loner::Helpers.mark_loner_as_unqueued( queue, item ) if item item end # # Overwriting original destroy method to mark all destroyed jobs as unqueued. # Because the original method only returns the amount of jobs destroyed, but not # the jobs themselves. Hence Resque::Plugins::Loner::Helpers.job_destroy looks almost # as the original method Resque::Job.destroy. Couldn't make it any dry'er. # def self.destroy_with_loner(queue, klass, *args) Resque::Plugins::Loner::Helpers.job_destroy(queue, klass, *args) destroy_without_loner(queue, klass, *args) end # # Chain.. # class << self alias_method :create_without_loner, :create alias_method :create, :create_with_loner alias_method :reserve_without_loner, :reserve alias_method :reserve, :reserve_with_loner alias_method :destroy_without_loner, :destroy alias_method :destroy, :destroy_with_loner end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
resque-loner-1.0.1 | lib/resque-ext/job.rb |