class Resque::Plugins::Batch::MessageHandler
idle_duration: Set this to a number
Attributes
exit_handler[RW]
idle_handler[RW]
init_handler[RW]
job_arrhythmia_handler[RW]
job_begin_handler[RW]
job_exception_handler[RW]
job_failure_handler[RW]
job_info_handler[RW]
job_success_handler[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/resque/plugins/batch/message_handler.rb, line 20 def initialize(options = {}) @init_handler = options.fetch(:init, ->(_batch){}) @exit_handler = options.fetch(:exit, ->(_batch){}) @idle_handler = options.fetch(:idle, ->(_batch, msg){}) # @info_handler = options.fetch(:info, ->(_batch, msg){}) @job_begin_handler = options.fetch(:job_begin, ->(_batch, _job_id){}) @job_success_handler = options.fetch(:job_success, ->(_batch, _job_id, _data){}) @job_failure_handler = options.fetch(:job_failure, ->(_batch, _job_id, _data){}) @job_exception_handler = options.fetch(:job_exception, ->(_batch, _job_id, _data){}) @job_info_handler = options.fetch(:job_info, ->(_batch, _job_id, _data){}) @job_arrhythmia_handler = options.fetch(:job_arrhythmia, ->(_batch, _job_id){}) end
Public Instance Methods
send_message(batch, type, msg = {})
click to toggle source
# File lib/resque/plugins/batch/message_handler.rb, line 35 def send_message(batch, type, msg = {}) case type when :init send_init(batch) when :exit send_exit(batch) when :idle send_idle(batch, msg) when :job send_job(batch, msg) else raise "unknown message type: #{type}" end end
Private Instance Methods
send_exit(batch)
click to toggle source
# File lib/resque/plugins/batch/message_handler.rb, line 56 def send_exit(batch) exit_handler.call(batch) end
send_idle(batch, msg)
click to toggle source
# File lib/resque/plugins/batch/message_handler.rb, line 60 def send_idle(batch, msg) idle_handler.call(batch, msg) end
send_init(batch)
click to toggle source
# File lib/resque/plugins/batch/message_handler.rb, line 52 def send_init(batch) init_handler.call(batch) end
send_job(batch, msg)
click to toggle source
def send_info(batch, msg) end
# File lib/resque/plugins/batch/message_handler.rb, line 67 def send_job(batch, msg) job_id = msg["job_id"] case msg["msg"] when "begin" job_begin_handler.call(batch, job_id) when "success" job_success_handler.call(batch, job_id, msg["data"]) when "failure" job_failure_handler.call(batch, job_id, msg["data"]) when "exception" job_exception_handler.call(batch, job_id, msg["data"]) when "info" job_info_handler.call(batch, job_id, msg["data"]) when "arrhythmia" job_arrhythmia_handler.call(batch, job_id) else raise "unknown msg type: #{msg["msg"]}" end end