Module: Resque::Plugins::UniqueJob::ClassMethods
- Defined in:
- lib/resque-loner/unique_job.rb
Overview
self.included
Instance Method Summary collapse
-
#loner_ttl ⇒ Object
The default ttl of a locking key is -1, i.e.
-
#redis_key_loner(payload) ⇒ Object
Payload is what Resque stored for this job along with the job’s class name.
Instance Method Details
#loner_ttl ⇒ Object
The default ttl of a locking key is -1, i.e. forever. If for some reason you only want the lock to be in place after a certain amount of time, just set a ttl for for your job. For example:
class FooJob
include Resque::Plugins::UniqueJob
@loner_ttl = 40
end
end
48 49 50 |
# File 'lib/resque-loner/unique_job.rb', line 48 def loner_ttl @loner_ttl || -1 end |
#redis_key_loner(payload) ⇒ Object
Payload is what Resque stored for this job along with the job’s class name.
On a Resque with no plugins installed, this is a hash containing :class and :args
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/resque-loner/unique_job.rb', line 25 def redis_key_loner(payload) payload = decode(encode(payload)) # This is the cycle the data goes when being enqueued/dequeued job = payload[:class] || payload["class"] args = (payload[:args] || payload["args"]) args.map! do |arg| arg.is_a?(Hash) ? arg.sort : arg end digest = Digest::MD5.hexdigest encode(:class => job, :args => args) digest end |