Class: Gongren::Rails::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/gongren/rails/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



10
11
12
13
# File 'lib/gongren/rails/server.rb', line 10

def initialize(options={})
  @options = options.symbolize_keys
  @logger  = options[:logger] || Rails.logger
end

Class Method Details

.start(options = {}) ⇒ Object

A quick way to instantiate a server with some options.



26
27
28
# File 'lib/gongren/rails/server.rb', line 26

def self.start(options={})
  new(options).start
end

.submit(name, unit) ⇒ Object

Submits a unit of work to the pool of workers.



16
17
18
19
20
21
22
23
# File 'lib/gongren/rails/server.rb', line 16

def self.submit(name, unit)
  data = Marshal.dump(unit)

  # NOTE: mandatory => true means return an error if the message can't be routed immediately.
  # This would indicate a configuration error, as workers should build their queue and
  # bind them to the exchange on startup.
  topic.publish(data, :persistent => true, :mandatory => true, :routing_key => "unit.#{name}")
end

Instance Method Details

#startObject

Starts the reactor / event loop.



31
32
33
34
35
# File 'lib/gongren/rails/server.rb', line 31

def start
  logger.info { "Gongren::Server #{Process.pid} starting" }
  Qusion.start(@options)
  self.class.control_topic # Instantiates the control topic, for later use
end