Module: Resque::Plugins::UniqueJob::ClassMethods

Defined in:
lib/resque_solo/unique_job.rb

Instance Method Summary collapse

Instance Method Details

#lock_after_execution_periodObject

The default ttl of a persisting key is 0, i.e. immediately deleted. Set lock_after_execution_period to block the execution of the job for a certain amount of time (in seconds). For example:

class FooJob

include Resque::Plugins::UniqueJob
@lock_after_execution_period = 40

end



47
48
49
# File 'lib/resque_solo/unique_job.rb', line 47

def lock_after_execution_period
  @lock_after_execution_period ||= 0
end

#redis_key(payload) ⇒ Object

Payload is what Resque stored for this job along with the job’s class name: a hash containing :class and :args



15
16
17
18
19
20
21
22
23
24
# File 'lib/resque_solo/unique_job.rb', line 15

def redis_key(payload)
  payload = Resque.decode(Resque.encode(payload))
  job  = payload["class"]
  args = payload["args"]
  args.map! do |arg|
    arg.is_a?(Hash) ? arg.sort : arg
  end

  Digest::MD5.hexdigest Resque.encode(class: job, args: args)
end

#ttlObject

The default ttl of a locking key is -1 (forever). To expire the lock after a certain amount of time, set a ttl (in seconds). For example:

class FooJob

include Resque::Plugins::UniqueJob
@ttl = 40

end



34
35
36
# File 'lib/resque_solo/unique_job.rb', line 34

def ttl
  @ttl ||= -1
end