Module: AcidicJob

Extended by:
ActiveSupport::Concern
Defined in:
lib/acidic_job/finished_point.rb,
lib/acidic_job.rb,
lib/acidic_job/run.rb,
lib/acidic_job/step.rb,
lib/acidic_job/errors.rb,
lib/acidic_job/staging.rb,
lib/acidic_job/version.rb,
lib/acidic_job/awaiting.rb,
lib/acidic_job/test_case.rb,
lib/acidic_job/recovery_point.rb,
lib/acidic_job/idempotency_key.rb,
lib/acidic_job/perform_wrapper.rb,
lib/acidic_job/upgrade_service.rb,
lib/acidic_job/extensions/noticed.rb,
lib/acidic_job/extensions/sidekiq.rb,
lib/acidic_job/extensions/active_job.rb,
lib/acidic_job/extensions/action_mailer.rb,
lib/generators/acidic_job/install_generator.rb,
lib/generators/acidic_job/drop_tables_generator.rb

Overview

Represents an action to set a new recovery point. One possible option for a return from an #atomic_phase block.

Defined Under Namespace

Modules: Awaiting, Extensions, Generators, PerformWrapper, Staging, UpgradeService Classes: Error, FinishedPoint, IdempotencyKey, Key, LockedIdempotencyKey, MismatchedIdempotencyKeyAndJobArguments, NoDefinedSteps, RecoveryPoint, Run, SerializedTransactionConflict, SidekiqBatchRequired, Staged, Step, TestCase, TooManyParametersForParallelJob, TooManyParametersForStepMethod, UnknownAtomicPhaseType, UnknownJobAdapter, UnknownRecoveryPoint, UnknownSerializedJobIdentifier

Constant Summary collapse

IDEMPOTENCY_KEY_LOCK_TIMEOUT =
90
VERSION =
"1.0.0.pre7"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wire_everything_up(klass) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/acidic_job.rb', line 26

def self.wire_everything_up(klass)
  # Ensure our `perform` method always runs first to gather parameters
  klass.prepend PerformWrapper

  klass.include Staging
  klass.include Awaiting

  # Add `deliver_acidicly` to ActionMailer
  ActionMailer::Parameterized::MessageDelivery.include Extensions::ActionMailer if defined?(ActionMailer)
  # Add `deliver_acidicly` to Noticed
  Noticed::Base.include Extensions::Noticed if defined?(Noticed)

  if defined?(ActiveJob) && klass < ActiveJob::Base
    klass.send(:include, Extensions::ActiveJob)
  elsif defined?(Sidekiq) && klass.include?(Sidekiq::Worker)
    klass.send(:include, Extensions::Sidekiq)
    klass.include ActiveSupport::Callbacks
    klass.define_callbacks :perform
  else
    raise UnknownJobAdapter
  end

  klass.set_callback :perform, :after, :delete_staged_job_record, if: :was_staged_job?
end

Instance Method Details

#idempotency_keyObject

rubocop:disable Naming/MemoizedInstanceVariableName



97
98
99
100
101
# File 'lib/acidic_job.rb', line 97

def idempotency_key
  return @__acidic_job_idempotency_key if defined? @__acidic_job_idempotency_key

  @__acidic_job_idempotency_key ||= IdempotencyKey.value_for(self, @__acidic_job_args, @__acidic_job_kwargs)
end

#idempotently(with:, &blk) ⇒ Object

DEPRECATED



86
87
88
# File 'lib/acidic_job.rb', line 86

def idempotently(with:, &blk)
  with_acidity(given: with, &blk)
end

#safely_finish_acidic_jobObject



90
91
92
93
94
# File 'lib/acidic_job.rb', line 90

def safely_finish_acidic_job
  # Short circuits execution by sending execution right to 'finished'.
  # So, ends the job "successfully"
  FinishedPoint.new
end

#with_acidity(given: {}) ⇒ Object

Raises:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/acidic_job.rb', line 62

def with_acidity(given: {})
  # execute the block to gather the info on what steps are defined for this job workflow
  @__acidic_job_steps = []
  steps = yield || []

  # check that the block actually defined at least one step
  # TODO: WRITE TESTS FOR FAULTY BLOCK VALUES
  raise NoDefinedSteps if @__acidic_job_steps.nil? || @__acidic_job_steps.empty?

  # convert the array of steps into a hash of recovery_points and next steps
  workflow = define_workflow(steps)

  # determine the idempotency key value for this job run (`job_id` or `jid`)
  # might be defined already in `identifier` method
  # TODO: allow idempotency to be defined by args OR job id
  @__acidic_job_idempotency_key ||= IdempotencyKey.value_for(self, @__acidic_job_args, @__acidic_job_kwargs)

  @run = ensure_run_record(@__acidic_job_idempotency_key, workflow, given)

  # begin the workflow
  process_run(@run)
end