Class: Sanford::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/sanford/manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_host, options = {}) ⇒ Manager

Returns a new instance of Manager.



24
25
26
27
# File 'lib/sanford/manager.rb', line 24

def initialize(service_host, options = {})
  @host = Sanford::HostData.new(service_host, options)
  @process_name = [ self.host.ip, self.host.port, self.host.name ].join('_')
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



22
23
24
# File 'lib/sanford/manager.rb', line 22

def host
  @host
end

#process_nameObject (readonly)

Returns the value of attribute process_name.



22
23
24
# File 'lib/sanford/manager.rb', line 22

def process_name
  @process_name
end

Class Method Details

.call(action, options = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sanford/manager.rb', line 10

def self.call(action, options = nil)
  options ||= {}
  options[:ip]    ||= ENV['SANFORD_IP']
  options[:port]  ||= ENV['SANFORD_PORT']

  name = options.delete(:host) || ENV['SANFORD_HOST']
  service_host = name ? Sanford.hosts.find(name) : Sanford.hosts.first
  raise(Sanford::NoHostError.new(name)) if !service_host

  self.new(service_host, options).call(action)
end

Instance Method Details

#call(action) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/sanford/manager.rb', line 29

def call(action)
  daemons_options = self.default_options.merge({ :ARGV => [ action.to_s ] })
  FileUtils.mkdir_p(daemons_options[:dir])
  ::Daemons.run_proc(self.process_name, daemons_options) do
    server = Sanford::Server.new(self.host)
    server.start
    server.join_thread
  end
end