Class: Gongren::Server
- Inherits:
-
Object
- Object
- Gongren::Server
- Defined in:
- lib/gongren/server.rb
Class Method Summary collapse
-
.start(options = {}, &block) ⇒ Object
A quick way to instantiate a server with some options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
-
#start ⇒ Object
Starts the reactor / event loop.
- #submit(name, message) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
6 7 8 9 |
# File 'lib/gongren/server.rb', line 6 def initialize(={}) @options = .inject(Hash.new) {|memo, (k,v)| memo[k.to_sym] = v; memo} # #symbolize_keys @logger = [:logger] || Logger.new([:log] || STDERR) end |
Class Method Details
.start(options = {}, &block) ⇒ Object
A quick way to instantiate a server with some options.
12 13 14 |
# File 'lib/gongren/server.rb', line 12 def self.start(={}, &block) new().start(&block) end |
Instance Method Details
#start ⇒ Object
Starts the reactor / event loop. This method never returns. Must pass a block to yield to, enabling you to do useful work. The block must return a 2 element Array: ["name of work unit", object]
You must provide a block to which an instance of Gongren::Server will be yielded.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gongren/server.rb', line 22 def start logger.info { "Gongren::Server #{Process.pid} starting with options: #{.inspect}" } AMQP.start() do @units = MQ.topic(exchange_name, ) @control = MQ.topic(control_exchange_name, ) yield self end end |
#submit(name, message) ⇒ Object
33 34 35 36 37 |
# File 'lib/gongren/server.rb', line 33 def submit(name, ) logger.debug { "Submitting #{name.inspect}: #{.inspect}" } data = Marshal.dump() @units.publish(data, :persistent => true, :key => "unit.#{name}") end |