Module: Resque::Plugins::UniqueInQueue::ClassMethods

Defined in:
lib/resque/plugins/unique_in_queue.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::UniqueInQueue
@lock_after_execution_period = 40

end



59
60
61
# File 'lib/resque/plugins/unique_in_queue.rb', line 59

def lock_after_execution_period
  @lock_after_execution_period ||= Resque::UniqueInQueue.uniq_config&.lock_after_execution_period
end

#redis_key(payload) ⇒ Object

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



27
28
29
30
31
32
33
34
35
36
# File 'lib/resque/plugins/unique_in_queue.rb', line 27

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::UniqueInQueue
@ttl = 40

end



46
47
48
# File 'lib/resque/plugins/unique_in_queue.rb', line 46

def ttl
  @ttl ||= Resque::UniqueInQueue.uniq_config&.ttl
end

#unique_in_queue_key_baseObject

Can’t be overridden per each class because it wouldn’t make sense. It wouldn’t be able to determine or enforce uniqueness across queues,

and general cleanup of stray keys would be nearly impossible.


66
67
68
# File 'lib/resque/plugins/unique_in_queue.rb', line 66

def unique_in_queue_key_base
  Resque::UniqueInQueue.uniq_config&.unique_in_queue_key_base
end

#unique_in_queue_redis_key(queue, item) ⇒ Object



21
22
23
# File 'lib/resque/plugins/unique_in_queue.rb', line 21

def unique_in_queue_redis_key(queue, item)
  "#{unique_in_queue_key_base}:queue:#{queue}:job:#{Resque::UniqueInQueue::Queue.const_for(item).redis_key(item)}"
end