Class: Falcon::Service::Supervisor
- Inherits:
-
Generic
- Object
- Generic
- Falcon::Service::Supervisor
show all
- Defined in:
- lib/falcon/service/supervisor.rb
Instance Method Summary
collapse
Methods inherited from Generic
#include?, #logger, #name, wrap
Constructor Details
#initialize(environment) ⇒ Supervisor
Returns a new instance of Supervisor.
30
31
32
33
34
|
# File 'lib/falcon/service/supervisor.rb', line 30
def initialize(environment)
super
@bound_endpoint = nil
end
|
Instance Method Details
#do_metrics(message) ⇒ Object
53
54
55
|
# File 'lib/falcon/service/supervisor.rb', line 53
def do_metrics(message)
Process::Metrics.capture(pid: Process.ppid, ppid: Process.ppid)
end
|
#do_restart(message) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/falcon/service/supervisor.rb', line 40
def do_restart(message)
signal = message[:signal] || :INT
Process.kill(signal, -Process.getpgrp)
end
|
#endpoint ⇒ Object
36
37
38
|
# File 'lib/falcon/service/supervisor.rb', line 36
def endpoint
@evaluator.endpoint
end
|
#handle(message) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/falcon/service/supervisor.rb', line 57
def handle(message)
case message[:please]
when 'restart'
self.do_restart(message)
when 'metrics'
self.do_metrics(message)
end
end
|
#setup(container) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/falcon/service/supervisor.rb', line 76
def setup(container)
container.run(name: self.name, restart: true, count: 1) do |instance|
Async do
@bound_endpoint.accept do |peer|
stream = Async::IO::Stream.new(peer)
while message = stream.gets("\0")
response = handle(JSON.parse(message, symbolize_names: true))
stream.puts(response.to_json, separator: "\0")
end
end
instance.ready!
end
end
super
end
|
#start ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/falcon/service/supervisor.rb', line 66
def start
Async.logger.info(self) {"Binding to #{self.endpoint}..."}
@bound_endpoint = Async::Reactor.run do
Async::IO::SharedEndpoint.bound(self.endpoint)
end.wait
super
end
|
#stop ⇒ Object
95
96
97
98
99
100
|
# File 'lib/falcon/service/supervisor.rb', line 95
def stop
@bound_endpoint&.close
@bound_endpoint = nil
super
end
|