module JobDispatch
Constants
- VERSION
Public Class Methods
config()
click to toggle source
# File lib/job_dispatch.rb, line 28 def config Configuration.config end
configure(&block)
click to toggle source
# File lib/job_dispatch.rb, line 24 def configure(&block) Configuration.configure(&block) end
context()
click to toggle source
@return [ZMQ::Context] return or create a ZeroMQ context.
# File lib/job_dispatch.rb, line 48 def context ZMQ.context || ZMQ::Context.new end
enqueue(job_attrs)
click to toggle source
# File lib/job_dispatch.rb, line 73 def enqueue(job_attrs) address = JobDispatch.config.broker[:connect] socket = JobDispatch.context.socket(ZMQ::REQ) socket.connect(address) socket.send(JSON.dump({command:'enqueue',job:job_attrs})) result = JSON.parse(socket.recv) socket.close result end
idle()
click to toggle source
# File lib/job_dispatch.rb, line 52 def idle "idle, doing nothing" end
load_config(hash)
click to toggle source
# File lib/job_dispatch.rb, line 39 def load_config(hash) configure do |c| hash.each_pair do |key, value| c[key] = value end end end
load_config_from_yml(filename='config/job_dispatch.yml', environment="default")
click to toggle source
# File lib/job_dispatch.rb, line 32 def load_config_from_yml(filename='config/job_dispatch.yml', environment="default") require 'yaml' _config = YAML.load_file(filename).with_indifferent_access _config = _config[environment] || _config[:default] load_config(_config) end
signal(queue='default')
click to toggle source
This signals to the job broker(s) that there are jobs immediately available on the given queue.
# File lib/job_dispatch.rb, line 61 def signal(queue='default') self.signaller ||= if config.signaller && config.signaller[:connect] signaller = JobDispatch::Signaller.new(config.signaller[:connect]) signaller.connect signaller else Null::Object.instance end self.signaller.signal(queue) end
unknown_command(params)
click to toggle source
# File lib/job_dispatch.rb, line 56 def unknown_command(params) puts "Unknown command: #{params.inspect}" end
Private Instance Methods
config()
click to toggle source
# File lib/job_dispatch.rb, line 28 def config Configuration.config end
configure(&block)
click to toggle source
# File lib/job_dispatch.rb, line 24 def configure(&block) Configuration.configure(&block) end
context()
click to toggle source
@return [ZMQ::Context] return or create a ZeroMQ context.
# File lib/job_dispatch.rb, line 48 def context ZMQ.context || ZMQ::Context.new end
enqueue(job_attrs)
click to toggle source
# File lib/job_dispatch.rb, line 73 def enqueue(job_attrs) address = JobDispatch.config.broker[:connect] socket = JobDispatch.context.socket(ZMQ::REQ) socket.connect(address) socket.send(JSON.dump({command:'enqueue',job:job_attrs})) result = JSON.parse(socket.recv) socket.close result end
idle()
click to toggle source
# File lib/job_dispatch.rb, line 52 def idle "idle, doing nothing" end
load_config(hash)
click to toggle source
# File lib/job_dispatch.rb, line 39 def load_config(hash) configure do |c| hash.each_pair do |key, value| c[key] = value end end end
load_config_from_yml(filename='config/job_dispatch.yml', environment="default")
click to toggle source
# File lib/job_dispatch.rb, line 32 def load_config_from_yml(filename='config/job_dispatch.yml', environment="default") require 'yaml' _config = YAML.load_file(filename).with_indifferent_access _config = _config[environment] || _config[:default] load_config(_config) end
signal(queue='default')
click to toggle source
This signals to the job broker(s) that there are jobs immediately available on the given queue.
# File lib/job_dispatch.rb, line 61 def signal(queue='default') self.signaller ||= if config.signaller && config.signaller[:connect] signaller = JobDispatch::Signaller.new(config.signaller[:connect]) signaller.connect signaller else Null::Object.instance end self.signaller.signal(queue) end
unknown_command(params)
click to toggle source
# File lib/job_dispatch.rb, line 56 def unknown_command(params) puts "Unknown command: #{params.inspect}" end