Class: Delayed::Backend::ActiveRecord::Job

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/delayed_job_loner/init.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lonerObject

Returns the value of attribute loner.



7
8
9
# File 'lib/delayed_job_loner/init.rb', line 7

def loner
  @loner
end

#unique_onObject

Returns the value of attribute unique_on.



8
9
10
# File 'lib/delayed_job_loner/init.rb', line 8

def unique_on
  @unique_on
end

Instance Method Details

#check_uniquenessObject



12
13
14
15
16
17
18
19
# File 'lib/delayed_job_loner/init.rb', line 12

def check_uniqueness
  if loner || unique_on
    self.loner_hash = generate_loner_hash
    self.errors.add(:base, "Job already exists") unless self.class.where(loner_hash: self.loner_hash, locked_by: nil).first.nil?
  else
    true
  end
end

#generate_loner_hashObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/delayed_job_loner/init.rb', line 21

def generate_loner_hash
  if unique_on
    hashable_string = "#{payload_object.method_name}"
    unique_on.each do |attribute_name|
      hashable_string += "::#{attribute_name}:#{payload_object.send(attribute_name)}"
    end
  else
    hashable_string = "#{payload_object.method_name}::id:#{payload_object.id}"
  end
  Digest::MD5.base64digest(hashable_string)
end