Sha256: 32dd660d78d1de821a66099595bbdbdb2ede65ed20299a89fc3e9d593da9dabf

Contents?: true

Size: 738 Bytes

Versions: 19

Compression:

Stored size: 738 Bytes

Contents

# frozen_string_literal: true

module AcidicJob
  class IdempotencyKey
    def initialize(job)
      @job = job
    end

    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
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
acidic_job-0.9.0 lib/acidic_job/idempotency_key.rb
acidic_job-0.8.8 lib/acidic_job/idempotency_key.rb
acidic_job-0.8.7 lib/acidic_job/idempotency_key.rb
acidic_job-0.8.5 lib/acidic_job/idempotency_key.rb
acidic_job-0.8.4 lib/acidic_job/idempotency_key.rb
acidic_job-0.8.3 lib/acidic_job/idempotency_key.rb
acidic_job-0.8.2 lib/acidic_job/idempotency_key.rb
acidic_job-0.8.1 lib/acidic_job/idempotency_key.rb
acidic_job-0.8.0 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.10 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.9 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.8 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.7 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.6 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.5 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.4 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.3 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.2 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.beta.1 lib/acidic_job/idempotency_key.rb