Class: Failbot::Server

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

Overview

Interface for starting the exception relay server. This class constructs a temporary config file for ernie and starts the erlang server process.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port = nil, tmpdir = nil) ⇒ Server

Returns a new instance of Server.



8
9
10
11
# File 'lib/failbot/server.rb', line 8

def initialize(port=nil, tmpdir=nil)
  @port = (port || 6666).to_i
  @tmp = tmpdir || Dir.tmpdir
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#tmpObject (readonly)

Returns the value of attribute tmp.



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

def tmp
  @tmp
end

Instance Method Details

#config_fileObject



33
34
35
# File 'lib/failbot/server.rb', line 33

def config_file
  "#{@tmp}/ernie.failbot.#{Failbot.environment}.cfg"
end

#configureObject



28
29
30
31
# File 'lib/failbot/server.rb', line 28

def configure
  write_config
  config_file
end

#exec!Object



48
49
50
51
# File 'lib/failbot/server.rb', line 48

def exec!
  configure
  exec "ernie", "-p", port.to_s, "-P", pid_file, "-d", "-c", config_file
end

#handler_fileObject



20
21
22
# File 'lib/failbot/server.rb', line 20

def handler_file
  File.expand_path('../handler.rb', __FILE__)
end

#pid_fileObject



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

def pid_file
  "#{@tmp}/failbot.#{port}.pid"
end

#workersObject



16
17
18
# File 'lib/failbot/server.rb', line 16

def workers
  Failbot.config['workers'] || 1
end

#write_configObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/failbot/server.rb', line 37

def write_config
  File.open(config_file, 'wb') do |io|
    io.write((<<-ERLANG).gsub(/^ {10}/, ''))
      [{module, failbot},
       {type, external},
       {command, "ruby #{handler_file}"},
       {count, #{workers}}].
    ERLANG
  end
end