module Resque::Plugins::Batch::Job::ClassMethods

Public Instance Methods

perform(batch_id, job_id, *params) click to toggle source
# File lib/resque/plugins/batch/job.rb, line 12
def perform(batch_id, job_id, *params)
  heartbeat_thread = nil

  @worker_job_info = Resque::Plugins::Batch::WorkerJobInfo.new(batch_id, job_id)

  @worker_job_info.heartbeat!

  heartbeat_thread = Thread.new do
    loop do
      sleep(Resque::Plugins::Batch::JOB_HEARTBEAT)
      @worker_job_info.heartbeat!
    end
  end

  begin
    @worker_job_info.begin!

    success, data = perform_work(*params)

    if success
      @worker_job_info.success!(data)
    else
      @worker_job_info.failure!(data)
    end
  rescue StandardError => exception
    @worker_job_info.exception!(exception)
    raise exception
  end
ensure
  if heartbeat_thread
    heartbeat_thread.exit
  end
end