class Resque::Plugins::Batch::WorkerJobInfo
This class will be instantiated in a job and can be used to interact with the batch (by passing messages to a redis list)
Attributes
batch_id[R]
job_id[R]
Public Class Methods
new(batch_id, job_id)
click to toggle source
# File lib/resque/plugins/batch/worker_job_info.rb, line 9 def initialize(batch_id, job_id) @batch_id = batch_id @job_id = job_id end
Public Instance Methods
begin!()
click to toggle source
# File lib/resque/plugins/batch/worker_job_info.rb, line 14 def begin! redis.rpush(batch_key, Resque.encode(job_id: job_id, msg: 'begin')) end
exception!(exception)
click to toggle source
# File lib/resque/plugins/batch/worker_job_info.rb, line 26 def exception!(exception) redis.rpush(batch_key, Resque.encode(job_id: job_id, msg: 'exception', data: {class: exception.class.name, message: exception.message, backtrace: exception.backtrace})) end
failure!(data)
click to toggle source
# File lib/resque/plugins/batch/worker_job_info.rb, line 22 def failure!(data) redis.rpush(batch_key, Resque.encode(job_id: job_id, msg: 'failure', data: data)) end
heartbeat!()
click to toggle source
# File lib/resque/plugins/batch/worker_job_info.rb, line 35 def heartbeat! redis.set(heartbeat_key, "running") redis.expire(heartbeat_key, Resque::Plugins::Batch::JOB_HEARTBEAT_TTL) end
info!(data)
click to toggle source
NOTE: This is the only message that the client should send
# File lib/resque/plugins/batch/worker_job_info.rb, line 31 def info!(data) redis.rpush(batch_key, Resque.encode(job_id: job_id, msg: 'info', data: data)) end
success!(data)
click to toggle source
# File lib/resque/plugins/batch/worker_job_info.rb, line 18 def success!(data) redis.rpush(batch_key, Resque.encode(job_id: job_id, msg: 'success', data: data)) end
Private Instance Methods
batch_key()
click to toggle source
# File lib/resque/plugins/batch/worker_job_info.rb, line 46 def batch_key "batch:#{batch_id}" end
heartbeat_key()
click to toggle source
# File lib/resque/plugins/batch/worker_job_info.rb, line 50 def heartbeat_key "batch:#{batch_id}:heartbeat:#{job_id}" end
redis()
click to toggle source
# File lib/resque/plugins/batch/worker_job_info.rb, line 42 def redis Resque.redis end