Module: Resque::Plugins::UniqueInQueue::ClassMethods
- Defined in:
- lib/resque/plugins/unique_in_queue.rb
Instance Method Summary collapse
-
#lock_after_execution_period ⇒ Object
The default ttl of a persisting key is 0, i.e.
-
#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'.
-
#ttl ⇒ Object
The default ttl of a locking key is -1 (forever).
-
#unique_in_queue_key_base ⇒ Object
Should not generally be overridden per each class because it wouldn't make sense.
-
#unique_in_queue_redis_key(queue, item) ⇒ Object
The plugin stores per-job configuration on the job class.
Instance Method Details
#lock_after_execution_period ⇒ Object
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
49 50 51 52 |
# File 'lib/resque/plugins/unique_in_queue.rb', line 49 def lock_after_execution_period instance_variable_get(:@lock_after_execution_period) || instance_variable_set(:@lock_after_execution_period, Resque::UniqueInQueue.configuration&.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'
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/resque/plugins/unique_in_queue.rb', line 29 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 |
#ttl ⇒ Object
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
62 63 64 65 |
# File 'lib/resque/plugins/unique_in_queue.rb', line 62 def ttl instance_variable_get(:@ttl) || instance_variable_set(:@ttl, Resque::UniqueInQueue.configuration&.ttl) end |
#unique_in_queue_key_base ⇒ Object
Should not generally 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.
71 72 73 74 |
# File 'lib/resque/plugins/unique_in_queue.rb', line 71 def unique_in_queue_key_base instance_variable_get(:@unique_in_queue_key_base) || instance_variable_set(:@unique_in_queue_key_base, Resque::UniqueInQueue.configuration&.unique_in_queue_key_base) end |
#unique_in_queue_redis_key(queue, item) ⇒ Object
The plugin stores per-job configuration on the job class. rubocop:disable ThreadSafety/ClassInstanceVariable
23 24 25 |
# File 'lib/resque/plugins/unique_in_queue.rb', line 23 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 |