Module: AcidicJob::Mixin

Extended by:
ActiveSupport::Concern
Included in:
ActiveKiq, Base
Defined in:
lib/acidic_job/mixin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wire_up(other) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/acidic_job/mixin.rb', line 9

def self.wire_up(other)
  # Ensure our `perform` method always runs first to gather parameters
  # and run perform callbacks for Sidekiq workers
  other.prepend PerformWrapper

  # By default, we unique job runs by the `job_id`
  other.instance_variable_set(:@acidic_identifier, :job_id)
  # However, you can customize this behavior on a per job class level
  other.define_singleton_method(:acidic_by_job_identifier) { @acidic_identifier = :job_id }
  # You could unique job runs by the arguments passed to the job (e.g. memoization)
  other.define_singleton_method(:acidic_by_job_arguments) { @acidic_identifier = :job_arguments }
  # Or, you could unique jobs run by any logic you'd like using a block
  other.define_singleton_method(:acidic_by) { |&block| @acidic_identifier = block }

  # We add a callback to ensure that staged, non-workflow jobs are "finished" after they are "performed".
  # This allows us to ensure that we can always inspect whether a run is finished and get correct data
  other.set_callback :perform, :after, :finish_staged_job, if: -> { was_staged_job? && !was_workflow_job? }
  # We also allow you to write any of your own callbacks keyed to the "finish" event.
  # The "finish" event is notably different from the "perform" event for acidic jobs,
  # as any acidic job can have one or more "perform" event (retries or a resume after awaiting jobs),
  # but will only ever have one "finish" event (when the run successfully completes)
  other.define_callbacks :finish
end

Instance Method Details

#idempotency_keyObject



63
64
65
# File 'lib/acidic_job/mixin.rb', line 63

def idempotency_key
  IdempotencyKey.new(self).value(acidic_by: acidic_identifier)
end