class Resque::Plugins::Batch::BatchJobInfo
A batch uses this file to store the state of each job. As messages are received (through redis) they're used to update this data.
Attributes
args[R]
batch_id[R]
duration[R]
exception[R]
job_id[R]
klass[R]
result[R]
status[R]
Public Class Methods
new(batch_id, job_id, klass, *args)
click to toggle source
# File lib/resque/plugins/batch/batch_job_info.rb, line 17 def initialize(batch_id, job_id, klass, *args) @batch_id = batch_id @job_id = job_id @klass = klass @args = args @status = 'pending' end
Public Instance Methods
complete?()
click to toggle source
# File lib/resque/plugins/batch/batch_job_info.rb, line 33 def complete? ['success', 'failure', 'exception'].include?(status) end
heartbeat_running?()
click to toggle source
# File lib/resque/plugins/batch/batch_job_info.rb, line 41 def heartbeat_running? redis.get(heartbeat_key) == "running" end
incomplete?()
click to toggle source
# File lib/resque/plugins/batch/batch_job_info.rb, line 37 def incomplete? !complete? && status != 'unknown' end
process_job_msg(job_msg)
click to toggle source
Process the msg sent from WorkerJobInfo
# File lib/resque/plugins/batch/batch_job_info.rb, line 46 def process_job_msg(job_msg) msg = job_msg["msg"] data = job_msg["data"] if status == 'pending' && msg == 'begin' @status = 'running' @start_time = Time.now elsif (status == 'running' || status == 'unknown') && (msg == 'success' || msg == 'failure') @status = msg @result = data @duration = Time.now - @start_time elsif (status == 'running' || status == 'unknown') && msg == 'exception' @status = 'exception' @exception = data @duration = Time.now - @start_time elsif msg == "info" # Ignore client defined messages true elsif msg == "arrhythmia" @status = 'unknown' @duration = Time.now - @start_time else raise "State machine Error #{job_msg}" end end
running?()
click to toggle source
# File lib/resque/plugins/batch/batch_job_info.rb, line 25 def running? status == 'running' end
success?()
click to toggle source
# File lib/resque/plugins/batch/batch_job_info.rb, line 29 def success? status == 'success' end
Private Instance Methods
heartbeat_key()
click to toggle source
# File lib/resque/plugins/batch/batch_job_info.rb, line 78 def heartbeat_key "batch:#{batch_id}:heartbeat:#{job_id}" end
redis()
click to toggle source
# File lib/resque/plugins/batch/batch_job_info.rb, line 74 def redis Resque.redis end