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/testing.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, Testing, 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.pre16"
Class Method Summary collapse
Instance Method Summary collapse
-
#idempotency_key ⇒ Object
rubocop:disable Naming/MemoizedInstanceVariableName.
-
#idempotently(with: {}, &blk) ⇒ Object
DEPRECATED.
- #initialize(*args, **kwargs) ⇒ Object
- #safely_finish_acidic_job ⇒ Object
- #with_acidity(providing: {}) ⇒ Object
Class Method Details
.wire_everything_up(klass) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/acidic_job.rb', line 28 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? klass.instance_variable_set(:@acidic_identifier, :job_id) klass.define_singleton_method(:acidic_by_job_id) { @acidic_identifier = :job_id } klass.define_singleton_method(:acidic_by_job_args) { @acidic_identifier = :job_args } klass.define_singleton_method(:acidic_by) { |proc| @acidic_identifier = proc } end |
Instance Method Details
#idempotency_key ⇒ Object
rubocop:disable Naming/MemoizedInstanceVariableName
116 117 118 119 120 121 122 123 124 |
# File 'lib/acidic_job.rb', line 116 def idempotency_key if defined?(@__acidic_job_idempotency_key) && !@__acidic_job_idempotency_key.nil? return @__acidic_job_idempotency_key end acidic_identifier = self.class.acidic_identifier @__acidic_job_idempotency_key ||= IdempotencyKey.new(acidic_identifier) .value_for(self, *@__acidic_job_args, **@__acidic_job_kwargs) end |
#idempotently(with: {}, &blk) ⇒ Object
DEPRECATED
104 105 106 107 |
# File 'lib/acidic_job.rb', line 104 def idempotently(with: {}, &blk) ActiveSupport::Deprecation.new("1.0", "AcidicJob").deprecation_warning(:idempotently) with_acidity(providing: with, &blk) end |
#initialize(*args, **kwargs) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/acidic_job.rb', line 73 def initialize(*args, **kwargs) # ensure this instance variable is always defined @__acidic_job_steps = [] @__acidic_job_args = args @__acidic_job_kwargs = kwargs if method(__method__).super_method.arity.zero? super() else super(*args, **kwargs) end end |
#safely_finish_acidic_job ⇒ Object
109 110 111 112 113 |
# File 'lib/acidic_job.rb', line 109 def safely_finish_acidic_job # Short circuits execution by sending execution right to 'finished'. # So, ends the job "successfully" FinishedPoint.new end |
#with_acidity(providing: {}) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/acidic_job.rb', line 86 def with_acidity(providing: {}) # execute the block to gather the info on what steps are defined for this job workflow 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(@__acidic_job_steps) @run = ensure_run_record(workflow, providing) # begin the workflow process_run(@run) end |