Class: MotherBrain::RestGateway

Inherits:
Reel::Rack::Server
  • Object
show all
Includes:
Logging
Defined in:
lib/mb/rest_gateway.rb

Constant Summary collapse

DEFAULT_PORT =
ENV["PORT"] ? ENV["PORT"].to_i : 26100
DEFAULT_OPTIONS =
{
  host: '0.0.0.0',
  port: DEFAULT_PORT,
  quiet: false
}.freeze
VALID_OPTIONS =
[
  :host,
  :port,
  :quiet
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup

Constructor Details

#initialize(options = {}) ⇒ RestGateway

Returns a new instance of RestGateway.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :host (String) — default: '0.0.0.0'
  • :port (Integer) — default: 26100
  • :quiet (Boolean) — default: false


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mb/rest_gateway.rb', line 51

def initialize(options = {})
  log.debug { "REST Gateway starting..." }

  options = DEFAULT_OPTIONS.merge(options.slice(*VALID_OPTIONS))
  app     = MB::API::Application.new

  # reel-rack uses Rack standard capitalizations in > 0.0.2
  options[:Host] = options[:host]
  options[:Port] = options[:port]

  log.info { "REST Gateway listening on #{options[:host]}:#{options[:port]}" }
  
  begin
    super(app, options)
  rescue Errno::EADDRINUSE
    log.fatal { "Port #{options[:port]} is already in use. Unable to start rest gateway." }
  end
end

Class Method Details

.instanceCelluloid::Actor(Gateway)

Returns:

  • (Celluloid::Actor(Gateway))

Raises:

  • (Celluloid::DeadActorError)

    if rest gateway has not been started



9
10
11
# File 'lib/mb/rest_gateway.rb', line 9

def instance
  MB::Application[:rest_gateway] or raise Celluloid::DeadActorError, "REST Gateway not running"
end

.start(options = {}) ⇒ Object

Note:

you probably don’t want to manually start the REST Gateway unless you are testing. Start the entire application with MB::Application.run

Start the REST Gateway and add it to the application’s registry.



17
18
19
# File 'lib/mb/rest_gateway.rb', line 17

def start(options = {})
  MB::Application[:rest_gateway] = new(options)
end

.stopObject

Note:

you probably don’t want to manually stop the REST Gateway unless you are testing. Stop the entire application with MB::Application.stop

Stop the currently running REST Gateway



25
26
27
# File 'lib/mb/rest_gateway.rb', line 25

def stop
  instance.shutdown
end