Class: Sidekiq::LockableJob::Middleware::Client::SetLocks

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/lockable_job/middleware/client/set_locks.rb

Instance Method Summary collapse

Instance Method Details

#call(worker_class, job, queue, redis_pool) { ... } ⇒ Hash, ...

If false or nil is returned, the job is not to be enqueued into redis, otherwise the block’s return value is returned

Parameters:

  • worker_class (String, Class)

    the string or class of the worker class being enqueued

  • job (Hash)

    the full job payload

  • queue (String)

    the name of the queue the job was pulled from

  • redis_pool (ConnectionPool)

    the redis pool

Yields:

  • the next middleware in the chain or the enqueuing of the job

Returns:

  • (Hash, FalseClass, nil)

    if false or nil is returned, the job is not to be enqueued into redis, otherwise the block’s return value is returned



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sidekiq/lockable_job/middleware/client/set_locks.rb', line 17

def call(worker_class, job, queue, redis_pool)
  worker_klass = worker_class.is_a?(String) ? worker_class.constantize : worker_class
  if worker_klass.respond_to?(:lockable_job_client_lock_keys)
    keys = worker_klass.send(:lockable_job_client_lock_keys, job['args'])
    keys = [keys] unless keys.nil? || keys.is_a?(Array)
    keys&.compact&.each do |key|
      worker_klass.current_lockable_job_lock_service.lock(key)
    end
  end
  yield
end