Class: ActiveJob::Uniqueness::LockKey

Inherits:
Object
  • Object
show all
Defined in:
lib/active_job/uniqueness/lock_key.rb

Constant Summary collapse

FALLBACK_ARGUMENTS_STRING =
'no_arguments'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_class_name: nil, arguments: nil) ⇒ LockKey

Returns a new instance of LockKey.



14
15
16
17
18
19
20
21
# File 'lib/active_job/uniqueness/lock_key.rb', line 14

def initialize(job_class_name: nil, arguments: nil)
  if arguments.present? && job_class_name.blank?
    raise ArgumentError, 'job_class_name is required if arguments given'
  end

  @job_class_name = job_class_name
  @arguments = arguments || []
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



12
13
14
# File 'lib/active_job/uniqueness/lock_key.rb', line 12

def arguments
  @arguments
end

#job_class_nameObject (readonly)

Returns the value of attribute job_class_name.



12
13
14
# File 'lib/active_job/uniqueness/lock_key.rb', line 12

def job_class_name
  @job_class_name
end

Instance Method Details

#lock_keyObject



23
24
25
26
27
28
29
# File 'lib/active_job/uniqueness/lock_key.rb', line 23

def lock_key
  [
    lock_prefix,
    normalized_job_class_name,
    arguments_key_part
  ].join(':')
end

#runtime_lock_keyObject

used only by :until_and_while_executing strategy



32
33
34
35
36
37
# File 'lib/active_job/uniqueness/lock_key.rb', line 32

def runtime_lock_key
  [
    lock_key,
    'runtime'
  ].join(':')
end

#wildcard_keyObject



39
40
41
42
43
44
45
# File 'lib/active_job/uniqueness/lock_key.rb', line 39

def wildcard_key
  [
    lock_prefix,
    normalized_job_class_name,
    arguments.any? ? "#{arguments_key_part}*" : '*'
  ].compact.join(':')
end