Job Callbacks

The Jobly::Job class supports these callback methods:

MethodDescription
beforeExecutes before the job starts
on_skipExecutes if skip_job was called from the before block
on_successExecutes after the job finishes, and only if it succeeds
on_failureExecutes after the job finishes, and only if it fails
afterExecutes after the job finishes, regardless of success or failure

Each callback method can either be a block or a symbol that points to a local method. WHen using a block, you will have the params variable available, with all the parameteres sent to the job.

For example:

class Greet < Jobly::Job
  before do
    logger.info "Starting with #{params[:message]}"
  end

  after :reboot_computer

  def execute(message: "Hello")
    puts message
  end

  def reboot_computer
    system "reboot"
  end
end

In order to conditionally skip a job from its before block, you can call skip_job. This will avoid running the job, and will execute the on_skip action and the after action, if present.