Class: SidekiqUniqueJobs::LockType

Inherits:
Object
  • Object
show all
Includes:
SidekiqWorkerMethods
Defined in:
lib/sidekiq_unique_jobs/lock_type.rb

Overview

Calculates the lock type

Instance Attribute Summary collapse

Attributes included from SidekiqWorkerMethods

#job_class

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SidekiqWorkerMethods

#after_unlock_hook, #default_job_options, #job_class_constantize, #job_method_defined?, #job_options, #sidekiq_job_class?

Constructor Details

#initialize(item) ⇒ LockType

Returns a new instance of LockType.

Parameters:

  • item (Hash)

    the Sidekiq job hash

Options Hash (item):

  • :lock (Symbol, nil)

    the type of lock to use.

  • :class (String)

    the class of the sidekiq worker



28
29
30
31
# File 'lib/sidekiq_unique_jobs/lock_type.rb', line 28

def initialize(item)
  @item = item
  self.job_class = item[CLASS]
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



23
24
25
# File 'lib/sidekiq_unique_jobs/lock_type.rb', line 23

def item
  @item
end

Class Method Details

.call(item) ⇒ Symbol, NilClass

Computes lock type from job arguments, sidekiq_options.

Returns:

  • (Symbol)

    the lock type

  • (NilClass)

    if no lock type is found.



17
18
19
# File 'lib/sidekiq_unique_jobs/lock_type.rb', line 17

def self.call(item)
  new(item).call
end

Instance Method Details

#callObject



33
34
35
# File 'lib/sidekiq_unique_jobs/lock_type.rb', line 33

def call
  item[LOCK] || job_options[LOCK] || default_job_options[LOCK]
end