module ActiveJob::Continuable
Active Job Continuable
The Continuable module provides the ability to track the progress of your jobs, and continue from where they left off if interrupted.
Mix ActiveJob::Continuable into your job to enable continuations.
See ActiveJob::Continuation for usage.
Attributes
The number of times the job has been resumed.
Public Class Methods
Source
# File lib/active_job/continuable.rb, line 23 def initialize(...) super(...) self.resumptions = 0 self.continuation = Continuation.new(self, {}) end
Calls superclass method
Public Instance Methods
Source
# File lib/active_job/continuable.rb, line 36 def step(step_name, start: nil, isolated: false, &block) unless block_given? step_method = method(step_name) raise ArgumentError, "Step method '#{step_name}' must accept 0 or 1 arguments" if step_method.arity > 1 if step_method.parameters.any? { |type, name| type == :key || type == :keyreq } raise ArgumentError, "Step method '#{step_name}' must not accept keyword arguments" end block = step_method.arity == 0 ? -> (_) { step_method.call } : step_method end checkpoint! if continuation.advanced? continuation.step(step_name, start: start, isolated: isolated, &block) end
Start a new continuation step
Private Instance Methods
Source
# File lib/active_job/continuable.rb, line 72 def continue(&block) if continuation.started? self.resumptions += 1 instrument :resume, **continuation.instrumentation end block.call rescue Continuation::Interrupt => e resume_job(e) rescue Continuation::Error raise rescue StandardError => e if resume_errors_after_advancing? && continuation.advanced? resume_job(exception: e) else raise end end