Module: Leveret::Job::InstanceMethods
- Defined in:
- lib/leveret/job.rb
Overview
Instance methods to mixin with your job
Instance Attribute Summary collapse
-
#params ⇒ Paramters
The parameters required for task execution.
Instance Method Summary collapse
-
#initialize(params = Parameters.new) ⇒ Object
Create a new job ready for execution.
-
#perform ⇒ Object
Run the job with no error handling.
-
#run ⇒ Symbol
Runs the job and captures any exceptions to turn them into symbols which represent the status of the job.
Instance Attribute Details
#params ⇒ Paramters
Returns 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
57 58 59 |
# File 'lib/leveret/job.rb', line 57 def initialize(params = Parameters.new) self.params = params end |
#perform ⇒ Object
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.
90 91 92 |
# File 'lib/leveret/job.rb', line 90 def perform raise NotImplementedError end |
#run ⇒ Symbol
Runs the job and captures any exceptions to turn them into symbols which represent the status of the job
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.} when processing #{self.class.name} with #{params}" Leveret.configuration.error_handler.call(e, self) :reject end |