Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce async-container-supervisor. #275

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions bake/falcon/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
# Copyright, 2020-2025, by Samuel Williams.

def restart
require_relative "../../lib/falcon/command/supervisor"

Falcon::Command::Supervisor["restart"].call
context.lookup("async:container:supervisor:restart").call
end
2 changes: 1 addition & 1 deletion examples/hello/falcon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# append preload "preload.rb"


include Async::Container::Supervisor::Supervised
end

service "supervisor" do
Expand Down
2 changes: 1 addition & 1 deletion falcon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ Gem::Specification.new do |spec|

spec.add_dependency "async"
spec.add_dependency "async-container", "~> 0.20"
spec.add_dependency "async-container-supervisor", "~> 0.4.0"
spec.add_dependency "async-http", "~> 0.75"
spec.add_dependency "async-http-cache", "~> 0.4"
spec.add_dependency "async-service", "~> 0.10"
spec.add_dependency "bundler"
spec.add_dependency "localhost", "~> 1.1"
spec.add_dependency "openssl", "~> 3.0"
spec.add_dependency "process-metrics", "~> 0.2"
spec.add_dependency "protocol-http", "~> 0.31"
spec.add_dependency "protocol-rack", "~> 0.7"
spec.add_dependency "samovar", "~> 2.3"
Expand Down
73 changes: 0 additions & 73 deletions lib/falcon/command/supervisor.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/falcon/command/top.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require_relative "virtual"
require_relative "proxy"
require_relative "redirect"
require_relative "supervisor"

require_relative "../version"

Expand Down Expand Up @@ -38,7 +37,6 @@ class Top < Samovar::Command
"virtual" => Virtual,
"proxy" => Proxy,
"redirect" => Redirect,
"supervisor" => Supervisor,
}, default: "serve"

# Whether verbose logging is enabled.
Expand Down
32 changes: 4 additions & 28 deletions lib/falcon/environment/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,18 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require_relative "../service/supervisor"
require_relative "../environment"

require "io/endpoint/unix_endpoint"
require "async/container/supervisor"

module Falcon
module Environment
# Provides an environment for hosting a supervisor which can monitor multiple applications.
module Supervisor
# The service class to use for the supervisor.
# @returns [Class]
def service_class
::Falcon::Service::Supervisor
end

# The name of the supervisor
# @returns [String]
def name
"supervisor"
end

# The IPC path to use for communication with the supervisor.
# @returns [String]
def ipc_path
::File.expand_path("supervisor.ipc", root)
end

# The endpoint the supervisor will bind to.
# @returns [::IO::Endpoint::Generic]
def endpoint
::IO::Endpoint.unix(ipc_path)
end
include Async::Container::Supervisor::Environment

# Options to use when creating the container.
def container_options
{restart: true, count: 1, health_check_timeout: 30}
def monitors
[Async::Container::Supervisor::MemoryMonitor.new(interval: 10)]
end
end

Expand Down
5 changes: 5 additions & 0 deletions lib/falcon/service/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright, 2020, by Daniel Evans.

require "async/service/generic"
require "async/container/supervisor/supervised"
require "async/http/endpoint"

require_relative "../server"
Expand Down Expand Up @@ -58,6 +59,10 @@ def setup(container)
evaluator = @environment.evaluator

Async do |task|
if @environment.implements?(Async::Container::Supervisor::Supervised)
evaluator.make_supervised_worker(instance).run
end

server = evaluator.make_server(@bound_endpoint)

server.run
Expand Down
123 changes: 0 additions & 123 deletions lib/falcon/service/supervisor.rb

This file was deleted.

27 changes: 27 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@

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

### Introduce `Async::Container::Supervisor`.

`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`.

By default, the supervisor does not perform any monitoring, but you may add monitoring by defining them in the service definition. For example:

``` ruby
service "hello.localhost" do
# Configure server...

include Async::Container::Supervisor::Supervised
end

service "supervisor" do
include Async::Container::Supervisor::Environment

monitors do
[
# Limit total memory usage to 512MiB:
Async::Container::Supervisor::MemoryMonitor.new(interval: 10, limit: 1024 * 1024 * 512),
]
end
end
```

We retain the `falcon:supervisor:restart` task, but you may prefer to use `async:container:supervisor:restart` directly.

## v0.50.0

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