Skip to content

Commit 3091586

Browse files
Rename async-services-supervisor.
1 parent 33487bb commit 3091586

33 files changed

+950
-1564
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# frozen_string_literal: true
22

3-
require_relative "lib/async/container/supervisor/version"
3+
require_relative "lib/async/services/supervisor/version"
44

55
Gem::Specification.new do |spec|
6-
spec.name = "async-container-supervisor"
7-
spec.version = Async::Container::Supervisor::VERSION
6+
spec.name = "async-services-supervisor"
7+
spec.version = Async::Services::Supervisor::VERSION
88

99
spec.summary = "A supervisor for managing multiple container processes."
1010
spec.authors = ["Samuel Williams"]
@@ -13,18 +13,19 @@ Gem::Specification.new do |spec|
1313
spec.cert_chain = ["release.cert"]
1414
spec.signing_key = File.expand_path("~/.gem/release.pem")
1515

16-
spec.homepage = "https://github.com/socketry/async-container-supervisor"
16+
spec.homepage = "https://github.com/socketry/async-services-supervisor"
1717

1818
spec.metadata = {
19-
"documentation_uri" => "https://socketry.github.io/async-container-supervisor/",
20-
"source_code_uri" => "https://github.com/socketry/async-container-supervisor.git",
19+
"documentation_uri" => "https://socketry.github.io/async-services-supervisor/",
20+
"source_code_uri" => "https://github.com/socketry/async-services-supervisor.git",
2121
}
2222

2323
spec.files = Dir.glob(["{bake,context,lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)
2424

2525
spec.required_ruby_version = ">= 3.2"
2626

27-
spec.add_dependency "async-service"
27+
spec.add_dependency "async-bus"
28+
spec.add_dependency "async-service", "~> 0.15"
2829
spec.add_dependency "io-endpoint"
2930
spec.add_dependency "memory", "~> 0.7"
3031
spec.add_dependency "memory-leak", "~> 0.5"
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@
66
def initialize(...)
77
super
88

9-
require "async/container/supervisor"
9+
require "async/services/supervisor"
1010
end
1111

1212
# Restart the container, typically causing it to exit (the parent process should then restart it).
1313
def restart
1414
client do |connection|
15-
connection.call(do: :restart)
15+
supervisor = connection[:supervisor]
16+
supervisor.restart
1617
end
1718
end
1819

1920
# Reload the services gracefully, allowing them to reconfigure without dropping connections.
2021
def reload
2122
client do |connection|
22-
connection.call(do: :restart, signal: :HUP)
23+
supervisor = connection[:supervisor]
24+
supervisor.restart(signal: :HUP)
2325
end
2426
end
2527

2628
def status
2729
client do |connection|
28-
connection.call(do: :status)
30+
supervisor = connection[:supervisor]
31+
supervisor.status
2932
end
3033
end
3134

@@ -35,27 +38,25 @@ def status
3538
# that are retained after garbage collection.
3639
#
3740
# @parameter duration [Integer] The duration in seconds to sample for (default: 10).
38-
# @parameter connection_id [String] The connection ID to target a specific worker.
41+
# @parameter connection_id [Integer] The connection ID to target a specific worker.
3942
def memory_sample(duration: 10, connection_id:)
4043
client do |connection|
4144
Console.info(self, "Sampling memory from worker...", duration: duration, connection_id: connection_id)
4245

43-
# Build the operation request:
44-
operation = {do: :memory_sample, duration: duration}
45-
46-
# Use the forward operation to proxy the request to a worker:
47-
return connection.call(do: :forward, operation: operation, connection_id: connection_id)
46+
supervisor = connection[:supervisor]
47+
worker = supervisor[connection_id]
48+
return worker.memory_sample(duration: duration)
4849
end
4950
end
5051

5152
private
5253

5354
def endpoint
54-
Async::Container::Supervisor.endpoint
55+
Async::Services::Supervisor.endpoint
5556
end
5657

5758
def client(&block)
5859
Sync do
59-
Async::Container::Supervisor::Client.new(endpoint: self.endpoint).connect(&block)
60+
Async::Services::Supervisor::Client.new(endpoint: self.endpoint).connect(&block)
6061
end
6162
end

fixtures/async/container/supervisor/a_monitor.rb renamed to fixtures/async/services/supervisor/a_monitor.rb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Released under the MIT License.
44
# Copyright, 2025, by Samuel Williams.
55

6-
require "async/container/supervisor/a_server"
6+
require "async/services/supervisor/a_server"
77

88
module Async
9-
module Container
9+
module Services
1010
module Supervisor
1111
AMonitor = Sus::Shared("a monitor") do
1212
include_context AServer
@@ -15,35 +15,38 @@ module Supervisor
1515

1616
it "can add and remove connections" do
1717
worker = Worker.new(endpoint: endpoint)
18-
connection = worker.connect
18+
worker_task = worker.run
1919

2020
event = registration_monitor.pop
2121
expect(event).to have_attributes(
2222
type: be == :register,
2323
)
24+
expect(event.supervisor_controller).to be_a(Async::Services::Supervisor::SupervisorController)
2425

25-
connection.close
26+
worker_task.stop
2627

2728
event = registration_monitor.pop
2829
expect(event).to have_attributes(
2930
type: be == :remove,
3031
)
3132
ensure
32-
connection&.close
33+
worker_task&.stop
3334
end
3435

3536
it "can respond to status calls" do
36-
worker = Worker.new(endpoint: endpoint)
37-
connection = worker.connect
38-
39-
response = connection.call(do: :status)
37+
client = Client.new(endpoint: endpoint)
4038

41-
# Maybe we could be a bit more specific.
42-
expect(response).to be_a(Array)
43-
ensure
44-
connection&.close
39+
client.connect do |connection|
40+
supervisor = connection[:supervisor]
41+
response = supervisor.status
42+
43+
# Status should return an array of monitor statuses
44+
expect(response).to be_a(Array)
45+
end
4546
end
4647
end
4748
end
4849
end
4950
end
51+
52+

fixtures/async/container/supervisor/a_server.rb renamed to fixtures/async/services/supervisor/a_server.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
# Copyright, 2025, by Samuel Williams.
55

66
require "sus/fixtures/async/scheduler_context"
7-
require "async/container/supervisor"
7+
require "async/services/supervisor"
88

99
require "io/endpoint/bound_endpoint"
1010
require "tmpdir"
1111

1212
module Async
13-
module Container
13+
module Services
1414
module Supervisor
1515
class RegistrationMonitor
16-
Event = Struct.new(:type, :connection)
16+
Event = Struct.new(:type, :supervisor_controller)
1717

1818
def initialize
1919
@registrations = ::Thread::Queue.new
@@ -24,28 +24,28 @@ def initialize
2424
def run
2525
end
2626

27-
def status(call)
28-
call.push(registrations: @registrations.size)
27+
def status
28+
{registrations: @registrations.size}
2929
end
3030

3131
def pop(...)
3232
@registrations.pop(...)
3333
end
3434

35-
def register(connection)
36-
@registrations << Event.new(:register, connection)
35+
def register(supervisor_controller)
36+
@registrations << Event.new(:register, supervisor_controller)
3737
end
3838

39-
def remove(connection)
40-
@registrations << Event.new(:remove, connection)
39+
def remove(supervisor_controller)
40+
@registrations << Event.new(:remove, supervisor_controller)
4141
end
4242
end
4343

4444
AServer = Sus::Shared("a server") do
4545
include Sus::Fixtures::Async::SchedulerContext
4646

4747
let(:ipc_path) {File.join(@root, "supervisor.ipc")}
48-
let(:endpoint) {Async::Container::Supervisor.endpoint(ipc_path)}
48+
let(:endpoint) {Async::Services::Supervisor.endpoint(ipc_path)}
4949

5050
def around
5151
Dir.mktmpdir do |directory|
@@ -56,7 +56,7 @@ def around
5656

5757
let(:registration_monitor) {RegistrationMonitor.new}
5858
let(:monitors) {[registration_monitor]}
59-
let(:server) {Async::Container::Supervisor::Server.new(endpoint: @bound_endpoint, monitors: monitors)}
59+
let(:server) {Async::Services::Supervisor::Server.new(endpoint: @bound_endpoint, monitors: monitors)}
6060

6161
def restart_supervisor
6262
@server_task&.stop
@@ -82,3 +82,4 @@ def restart_supervisor
8282
end
8383
end
8484
end
85+

lib/async/container/supervisor/client.rb

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)