Module: Leveret::Job::InstanceMethods

Defined in:
lib/leveret/job.rb

Overview

Instance methods to mixin with your job

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramsParamters

Returns The parameters required for task execution.

Returns:

  • (Paramters)

    The parameters required for task execution



52
53
54
# File 'lib/leveret/job.rb', line 52

def params
  @params
end

Instance Method Details

#initialize(params = Parameters.new) ⇒ Object

Create a new job ready for execution

Parameters:

  • params (Parameters) (defaults to: Parameters.new)

    Parameters to be consumed by #perform when performing the job



57
58
59
# File 'lib/leveret/job.rb', line 57

def initialize(params = Parameters.new)
  self.params = params
end

#performObject

Note:

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

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.

Raises:

  • (RequeueJob)

    Reject this job and put it back on the queue for future execution

  • (RejectJob)

    Reject this job and do not requeue it.



90
91
92
# File 'lib/leveret/job.rb', line 90

def perform
  raise NotImplementedError
end

#runSymbol

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

Returns:

  • (Symbol)

    :success, :requeue, :reject, :delay depending on job success



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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