Class: AcidicJob::IdempotencyKey

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

Instance Method Summary collapse

Constructor Details

#initialize(job) ⇒ IdempotencyKey

Returns a new instance of IdempotencyKey.



5
6
7
# File 'lib/acidic_job/idempotency_key.rb', line 5

def initialize(job)
  @job = job
end

Instance Method Details

#value(acidic_by: :job_id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/acidic_job/idempotency_key.rb', line 9

def value(acidic_by: :job_id)
  case acidic_by
  when Proc
    proc_result = @job.instance_exec(&acidic_by)
    Digest::SHA1.hexdigest [@job.class.name, proc_result].flatten.join
  when :job_arguments
    Digest::SHA1.hexdigest [@job.class.name, @job.arguments].flatten.join
  else
    if @job.job_id.start_with? Run::STAGED_JOB_ID_PREFIX
      # "STG__#{idempotency_key}__#{encoded_global_id}"
      _prefix, idempotency_key, _encoded_global_id = @job.job_id.split("__")
      idempotency_key
    else
      @job.job_id
    end
  end
end