Sha256: 1817ed47a3650af6bbf76f409b09a2d553a24b1718580a1e4e3ff9ed843f37a8

Contents?: true

Size: 893 Bytes

Versions: 9

Compression:

Stored size: 893 Bytes

Contents

# frozen_string_literal: true

module AcidicJob
  class IdempotencyKey
    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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
acidic_job-1.0.0.pre9 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.pre8 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.pre7 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.pre6 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.pre5 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.pre4 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.pre3 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.pre2 lib/acidic_job/idempotency_key.rb
acidic_job-1.0.0.pre1 lib/acidic_job/idempotency_key.rb