Module: JobDispatch

Extended by:
ActiveSupport::Autoload
Defined in:
lib/job_dispatch.rb,
lib/job_dispatch/job.rb,
lib/job_dispatch/broker.rb,
lib/job_dispatch/client.rb,
lib/job_dispatch/status.rb,
lib/job_dispatch/worker.rb,
lib/job_dispatch/version.rb,
lib/job_dispatch/identity.rb,
lib/job_dispatch/signaller.rb,
lib/job_dispatch/worker/item.rb,
lib/job_dispatch/client/proxy.rb,
lib/job_dispatch/broker/socket.rb,
lib/job_dispatch/configuration.rb,
lib/job_dispatch/worker/socket.rb,
lib/job_dispatch/broker/command.rb,
lib/job_dispatch/client/proxy_error.rb,
lib/job_dispatch/broker/internal_job.rb,
lib/job_dispatch/client/synchronous_proxy.rb

Defined Under Namespace

Modules: Job, Sockets Classes: Broker, Client, ClientError, Configuration, Identity, Signaller, Status, Worker

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.configObject



28
29
30
# File 'lib/job_dispatch.rb', line 28

def config
  Configuration.config
end

.configure(&block) ⇒ Object



24
25
26
# File 'lib/job_dispatch.rb', line 24

def configure(&block)
  Configuration.configure(&block)
end

.contextZMQ::Context

Return or create a ZeroMQ context.

Returns:

  • (ZMQ::Context)

    return or create a ZeroMQ context.



48
49
50
# File 'lib/job_dispatch.rb', line 48

def context
  ZMQ.context || ZMQ::Context.new
end

.enqueue(job_attrs) ⇒ Object



73
74
75
76
77
78
79
80
81
# 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

.idleObject



52
53
54
# File 'lib/job_dispatch.rb', line 52

def idle
  "idle, doing nothing"
end

.load_config(hash) ⇒ Object



39
40
41
42
43
44
45
# 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") ⇒ Object



32
33
34
35
36
37
# 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') ⇒ Object

This signals to the job broker(s) that there are jobs immediately available on the given queue.



61
62
63
64
65
66
67
68
69
70
# 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) ⇒ Object



56
57
58
# File 'lib/job_dispatch.rb', line 56

def unknown_command(params)
  puts "Unknown command: #{params.inspect}"
end