Class: AcidicJob::IdempotencyKey

Inherits:
Object
  • Object
show all
Defined in:
lib/acidic_job/idempotency_key.rb

Class Method Summary collapse

Class Method Details

.value_for(hash_or_job, *args, **kwargs) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/acidic_job/idempotency_key.rb', line 5

def self.value_for(hash_or_job, *args, **kwargs)
  return hash_or_job.job_id if hash_or_job.respond_to?(:job_id) && !hash_or_job.job_id.nil?
  return hash_or_job.jid if hash_or_job.respond_to?(:jid) && !hash_or_job.jid.nil?

  if hash_or_job.is_a?(Hash) && hash_or_job.key?("job_id") && !hash_or_job["job_id"].nil?
    return hash_or_job["job_id"]
  end
  return hash_or_job["jid"] if hash_or_job.is_a?(Hash) && hash_or_job.key?("jid") && !hash_or_job["jid"].nil?

  worker_class = case hash_or_job
                 when Hash
                   hash_or_job["worker"] || hash_or_job["job_class"]
                 else
                   hash_or_job.class.name
                 end

  Digest::SHA1.hexdigest [worker_class, args, kwargs].flatten.join
end