Class: AcidicJob::IdempotencyKey
- Inherits:
-
Object
- Object
- AcidicJob::IdempotencyKey
- Defined in:
- lib/acidic_job/idempotency_key.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(identifier = :job_id) ⇒ IdempotencyKey
constructor
A new instance of IdempotencyKey.
- #value_for(hash_or_job, *args, **kwargs) ⇒ Object
Constructor Details
#initialize(identifier = :job_id) ⇒ IdempotencyKey
Returns a new instance of IdempotencyKey.
9 10 11 |
# File 'lib/acidic_job/idempotency_key.rb', line 9 def initialize(identifier = :job_id) @identifier = identifier end |
Class Method Details
.generate(unique_by:, job_class:) ⇒ Object
5 6 7 |
# File 'lib/acidic_job/idempotency_key.rb', line 5 def self.generate(unique_by:, job_class:) new(:job_args).value_for({ "job_class" => job_class }, Marshal.dump(unique_by)) end |
Instance Method Details
#value_for(hash_or_job, *args, **kwargs) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/acidic_job/idempotency_key.rb', line 13 def value_for(hash_or_job, *args, **kwargs) return value_from_job_args(hash_or_job, *args, **kwargs) if @identifier == :job_args value = if hash_or_job.is_a?(Hash) value_from_job_id_for_hash(hash_or_job) else value_from_job_id_for_obj(hash_or_job) end value || value_from_job_args(hash_or_job, *args, **kwargs) end |