Class: Gongren::Server

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

Overview

This version is intimately tied to Rails.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



7
8
9
10
# File 'lib/gongren/server.rb', line 7

def initialize(options={})
  @options = options.inject(Hash.new) {|memo, (k,v)| memo[k.to_sym] = v; memo} # #symbolize_keys
  @logger  = options[:logger] || Logger.new(options[:log] || STDERR)
end

Class Method Details

.start(options = {}) ⇒ Object

A quick way to instantiate a server with some options.



19
20
21
# File 'lib/gongren/server.rb', line 19

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

.submit(name, unit) ⇒ Object

Submits a unit of work to the pool of workers.



13
14
15
16
# File 'lib/gongren/server.rb', line 13

def self.submit(name, unit)
  data = Marshal.dump(unit)
  topic.publish(data, :persistent => true, :key => "unit.#{name}")
end

Instance Method Details

#startObject

Starts the reactor / event loop.



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

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