class Executor
An executor for processing jobs using ActiveJob
.
Definitions
def initialize(delegate = nil)
Initialize the executor with an optional delegate.
Signature
-
parameter
delegate
Object
An optional delegate object for handling lifecycle methods.
Implementation
def initialize(delegate = nil)
@delegate = delegate
end
def execute(job_data)
Execute a job with the given data.
Signature
-
parameter
job_data
Hash
Serialized job data from ActiveJob.
Implementation
def execute(job_data)
::ActiveJob::Callbacks.run_callbacks(:execute) do
job = ::ActiveJob::Base.deserialize(job_data)
begin
job.perform_now
rescue => error
# Ignore, as ActiveJob has already logged the error.
end
end
end
def call(job)
Execute the given job.
Implementation
def call(job)
begin
execute(job)
rescue => error
# Error handling is done by the job itself.
# Ignore the error here, as ActiveJob has already logged unhandled errors.
Console::Event::Failure.for(error).emit(self, "Failed to execute job!", job: job)
end
@delegate&.call(job)
end
def start
Start the delegate if present.
Implementation
def start
@delegate&.start
end
def stop
Stop the delegate if present.
Implementation
def stop
@delegate&.stop
end
DEFAULT = self.new.freeze
The default executor, for use at the end of the queue.