Skip to content

Commit 26da475

Browse files
authored
Introduce async-container-supervisor. (#275)
1 parent be54958 commit 26da475

File tree

10 files changed

+55
-246
lines changed

10 files changed

+55
-246
lines changed

bake/falcon/supervisor.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44
# Copyright, 2020-2025, by Samuel Williams.
55

66
def restart
7-
require_relative "../../lib/falcon/command/supervisor"
8-
9-
Falcon::Command::Supervisor["restart"].call
7+
context.lookup("async:container:supervisor:restart").call
108
end

examples/hello/falcon.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# append preload "preload.rb"
2323

24-
24+
include Async::Container::Supervisor::Supervised
2525
end
2626

2727
service "supervisor" do

falcon.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ Gem::Specification.new do |spec|
2828

2929
spec.add_dependency "async"
3030
spec.add_dependency "async-container", "~> 0.20"
31+
spec.add_dependency "async-container-supervisor", "~> 0.4.0"
3132
spec.add_dependency "async-http", "~> 0.75"
3233
spec.add_dependency "async-http-cache", "~> 0.4"
3334
spec.add_dependency "async-service", "~> 0.10"
3435
spec.add_dependency "bundler"
3536
spec.add_dependency "localhost", "~> 1.1"
3637
spec.add_dependency "openssl", "~> 3.0"
37-
spec.add_dependency "process-metrics", "~> 0.2"
3838
spec.add_dependency "protocol-http", "~> 0.31"
3939
spec.add_dependency "protocol-rack", "~> 0.7"
4040
spec.add_dependency "samovar", "~> 2.3"

lib/falcon/command/supervisor.rb

-73
This file was deleted.

lib/falcon/command/top.rb

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
require_relative "virtual"
99
require_relative "proxy"
1010
require_relative "redirect"
11-
require_relative "supervisor"
1211

1312
require_relative "../version"
1413

@@ -38,7 +37,6 @@ class Top < Samovar::Command
3837
"virtual" => Virtual,
3938
"proxy" => Proxy,
4039
"redirect" => Redirect,
41-
"supervisor" => Supervisor,
4240
}, default: "serve"
4341

4442
# Whether verbose logging is enabled.

lib/falcon/environment/supervisor.rb

+4-28
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,18 @@
33
# Released under the MIT License.
44
# Copyright, 2019-2024, by Samuel Williams.
55

6-
require_relative "../service/supervisor"
76
require_relative "../environment"
87

9-
require "io/endpoint/unix_endpoint"
8+
require "async/container/supervisor"
109

1110
module Falcon
1211
module Environment
1312
# Provides an environment for hosting a supervisor which can monitor multiple applications.
1413
module Supervisor
15-
# The service class to use for the supervisor.
16-
# @returns [Class]
17-
def service_class
18-
::Falcon::Service::Supervisor
19-
end
20-
21-
# The name of the supervisor
22-
# @returns [String]
23-
def name
24-
"supervisor"
25-
end
26-
27-
# The IPC path to use for communication with the supervisor.
28-
# @returns [String]
29-
def ipc_path
30-
::File.expand_path("supervisor.ipc", root)
31-
end
32-
33-
# The endpoint the supervisor will bind to.
34-
# @returns [::IO::Endpoint::Generic]
35-
def endpoint
36-
::IO::Endpoint.unix(ipc_path)
37-
end
14+
include Async::Container::Supervisor::Environment
3815

39-
# Options to use when creating the container.
40-
def container_options
41-
{restart: true, count: 1, health_check_timeout: 30}
16+
def monitors
17+
[Async::Container::Supervisor::MemoryMonitor.new(interval: 10)]
4218
end
4319
end
4420

lib/falcon/service/server.rb

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Copyright, 2020, by Daniel Evans.
66

77
require "async/service/generic"
8+
require "async/container/supervisor/supervised"
89
require "async/http/endpoint"
910

1011
require_relative "../server"
@@ -58,6 +59,10 @@ def setup(container)
5859
evaluator = @environment.evaluator
5960

6061
Async do |task|
62+
if @environment.implements?(Async::Container::Supervisor::Supervised)
63+
evaluator.make_supervised_worker(instance).run
64+
end
65+
6166
server = evaluator.make_server(@bound_endpoint)
6267

6368
server.run

lib/falcon/service/supervisor.rb

-123
This file was deleted.

releases.md

+27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44

55
- Introduce {ruby Falcon::Environment::Server#make_server} which gives you full control over the server creation process.
66

7+
### Introduce `Async::Container::Supervisor`.
8+
9+
`Async::Container::Supervisor` is a new supervisor implementation that replaces Falcon's own supervisor. This allows you to use the same supervisor for all your services, and provides a more consistent interface for managing services. The supervisor is now a separate gem, `async-container-supervisor`.
10+
11+
By default, the supervisor does not perform any monitoring, but you may add monitoring by defining them in the service definition. For example:
12+
13+
``` ruby
14+
service "hello.localhost" do
15+
# Configure server...
16+
17+
include Async::Container::Supervisor::Supervised
18+
end
19+
20+
service "supervisor" do
21+
include Async::Container::Supervisor::Environment
22+
23+
monitors do
24+
[
25+
# Limit total memory usage to 512MiB:
26+
Async::Container::Supervisor::MemoryMonitor.new(interval: 10, limit: 1024 * 1024 * 512),
27+
]
28+
end
29+
end
30+
```
31+
32+
We retain the `falcon:supervisor:restart` task, but you may prefer to use `async:container:supervisor:restart` directly.
33+
734
## v0.50.0
835

936
- Add {ruby Falcon::Environment::Server#endpoint_options} to allow configuration of the endpoint options more easily.

0 commit comments

Comments
 (0)