module Leveret::Job::InstanceMethods

Instance methods to mixin with your job

Attributes

params[RW]

@!attribute params

@return [Paramters] The parameters required for task execution

Public Class Methods

new(params = Parameters.new) click to toggle source

Create a new job ready for execution

@param [Parameters] params Parameters to be consumed by {#perform} when performing the job

# File lib/leveret/job.rb, line 57
def initialize(params = Parameters.new)
  self.params = params
end

Public Instance Methods

perform() click to toggle source

Run the job with no error handling. Generally you should call {#run} to execute the job since that'll write and log output and call any error handlers if the job goes sideways.

@note Your class should override this method to contain the work to be done in this job.

@raise [RequeueJob] Reject this job and put it back on the queue for future execution @raise [RejectJob] Reject this job and do not requeue it.

# File lib/leveret/job.rb, line 90
def perform
  raise NotImplementedError
end
run() click to toggle source

Runs the job and captures any exceptions to turn them into symbols which represent the status of the job

@return [Symbol] :success, :requeue, :reject, :delay depending on job success

# File lib/leveret/job.rb, line 64
def run
  Leveret.log.info "Running #{self.class.name} with #{params}"
  perform
  :success
rescue Leveret::Job::RequeueJob
  Leveret.log.warn "Requeueing job #{self.class.name} with #{params}"
  :requeue
rescue Leveret::Job::RejectJob
  Leveret.log.warn "Rejecting job #{self.class.name} with #{params}"
  :reject
rescue Leveret::Job::DelayJob
  Leveret.log.warn "Delaying job #{self.class.name} with #{params}"
  :delay
rescue StandardError => e
  Leveret.log.error "#{e.message} when processing #{self.class.name} with #{params}"
  Leveret.configuration.error_handler.call(e, self)
  :reject
end