Job Callbacks

The Jobly::Job class supports these callback methods:

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 parameters sent to the job.

For example:

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

  after :reboot_computer

  def execute(message: "Hello")
    puts message

  def reboot_computer
    system "reboot"

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.