module Resque::Plugins::UniqueJob::ClassMethods

Public Instance Methods

loner_lock_after_execution_period() click to toggle source

The default ttl of a persisting key is 0, i.e. immediately deleted. You can set loner_lock_after_execution_period if you want to block the execution of the job for a certain amount of time (in seconds). For example:

class FooJob

include Resque::Plugins::UniqueJob
@loner_lock_after_execution_period = 40
end

end

# File lib/resque-loner/unique_job.rb, line 61
def loner_lock_after_execution_period
  @loner_lock_after_execution_period || 0
end
loner_ttl() click to toggle source

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 (in seconds) for your job. For example:

class FooJob

include Resque::Plugins::UniqueJob
@loner_ttl = 40
end

end

# File lib/resque-loner/unique_job.rb, line 46
def loner_ttl
  @loner_ttl || -1
end
redis_key(payload) click to toggle source

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

# File lib/resque-loner/unique_job.rb, line 23
def redis_key(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