Skip to content

Commit 6146b5e

Browse files
Rename back to original names names.
After much contemplation, I have decided I prefer the original taxonomy.
1 parent 0d2b580 commit 6146b5e

20 files changed

Lines changed: 351 additions & 302 deletions

File tree

context/best-practices.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Place environments in `lib/my_library/environment/`:
6161
module MyLibrary
6262
module Environment
6363
module WebEnvironment
64-
include Async::Service::ManagedEnvironment
64+
include Async::Service::Managed::Environment
6565

6666
def service_class
6767
MyLibrary::Service::WebService
@@ -87,7 +87,7 @@ Place services in `lib/my_library/service/`:
8787
# lib/my_library/service/web_service.rb
8888
module MyLibrary
8989
module Service
90-
class WebService < Async::Service::ManagedService
90+
class WebService < Async::Service::Managed::Service
9191
private def format_title(evaluator, server)
9292
if server&.respond_to?(:connection_count)
9393
"#{self.name} [#{evaluator.host}:#{evaluator.port}] (#{server.connection_count} connections)"
@@ -114,7 +114,7 @@ end
114114

115115
### Use `Managed::Environment` for Services
116116

117-
Include {ruby Async::Service::ManagedEnvironment} for services that need robust lifecycle management using {ruby Async::Service::ManagedService}:
117+
Include {ruby Async::Service::Managed::Environment} for services that need robust lifecycle management using {ruby Async::Service::Managed::Service}:
118118

119119
```ruby
120120
module WebEnvironment
@@ -201,7 +201,7 @@ end
201201

202202
### Use `Managed::Service` as Base Class
203203

204-
Prefer `Async::Service::ManagedService` over `Generic` for most services:
204+
Prefer `Async::Service::Managed::Service` over `Generic` for most services:
205205

206206
```ruby
207207
class WebService < Async::Service::ManagedService
@@ -243,7 +243,7 @@ module WebEnvironment
243243
end
244244
```
245245

246-
The `startup_timeout` ensures processes that hang during startup are detected, while `health_check_timeout` monitors processes after they've become ready. `ManagedService` automatically sends `status!` messages during startup to keep the health check clock resetting until the service is ready.
246+
The `startup_timeout` ensures processes that hang during startup are detected, while `health_check_timeout` monitors processes after they've become ready. `Managed::Service` automatically sends `status!` messages during startup to keep the health check clock resetting until the service is ready.
247247

248248
### Implement Meaningful Process Titles
249249

context/deployment.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require "async/http"
1414
require "async/service/managed_service"
1515
require "async/service/managed_environment"
1616

17-
class WebService < Async::Service::ManagedService
17+
class WebService < Async::Service::Managed::Service
1818
def start
1919
super
2020
@endpoint = @evaluator.endpoint
@@ -40,7 +40,7 @@ class WebService < Async::Service::ManagedService
4040
end
4141

4242
module WebEnvironment
43-
include Async::Service::ManagedEnvironment
43+
include Async::Service::Managed::Environment
4444

4545
def endpoint
4646
Async::HTTP::Endpoint.parse("http://0.0.0.0:3000")

context/service-architecture.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ end
262262

263263
### Health Checking
264264

265-
For services using `Async::Service::ManagedService`, health checking is handled automatically. The service sends `status!` messages during startup to prevent premature health check timeouts, then transitions to sending `ready!` messages once the service is actually ready.
265+
For services using `Async::Service::Managed::Service`, health checking is handled automatically. The service sends `status!` messages during startup to prevent premature health check timeouts, then transitions to sending `ready!` messages once the service is actually ready.
266266

267267
For services extending `Generic`, you can set up health checking manually:
268268

@@ -302,7 +302,7 @@ You can configure these timeouts via `container_options`:
302302

303303
```ruby
304304
module WebEnvironment
305-
include Async::Service::ManagedEnvironment
305+
include Async::Service::Managed::Environment
306306

307307
def container_options
308308
super.merge(
@@ -313,7 +313,7 @@ module WebEnvironment
313313
end
314314
```
315315

316-
Note: `Async::Service::ManagedService` automatically handles health checking, container options, and process title formatting, so you typically don't need to set this up manually.
316+
Note: `Async::Service::Managed::Service` automatically handles health checking, container options, and process title formatting, so you typically don't need to set this up manually.
317317

318318
## How They Work Together
319319

@@ -469,7 +469,7 @@ Create reusable configuration modules:
469469

470470
```ruby
471471
module ManagedEnvironment
472-
include Async::Service::ManagedEnvironment
472+
include Async::Service::Managed::Environment
473473

474474
def count
475475
4

examples/deployment/server.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# Copyright, 2025-2026, by Samuel Williams.
66

77
require "async/http"
8-
require "async/service/managed_service"
9-
require "async/service/managed_environment"
8+
require "async/service/managed/service"
9+
require "async/service/managed/environment"
1010

11-
class WebService < Async::Service::ManagedService
11+
class WebService < Async::Service::Managed::Service
1212
def start
1313
super
1414
@endpoint = @evaluator.endpoint
@@ -34,7 +34,7 @@ def run(instance, evaluator)
3434
end
3535

3636
module WebEnvironment
37-
include Async::Service::ManagedEnvironment
37+
include Async::Service::Managed::Environment
3838

3939
def endpoint
4040
Async::HTTP::Endpoint.parse("http://0.0.0.0:3000")

examples/ipc/service.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
require "socket"
88
require "async"
9-
require "async/service/managed_service"
10-
require "async/service/managed_environment"
9+
require "async/service/managed/service"
10+
require "async/service/managed/environment"
1111

1212
# Server service that listens on a Unix domain socket and responds with "Hello World"
13-
class IPCServer < Async::Service::ManagedService
13+
class IPCServer < Async::Service::Managed::Service
1414
def run(instance, evaluator)
1515
socket_path = evaluator.ipc_socket_path
1616

@@ -47,7 +47,7 @@ def run(instance, evaluator)
4747
end
4848

4949
# Client service that periodically connects to the server
50-
class IPCClient < Async::Service::ManagedService
50+
class IPCClient < Async::Service::Managed::Service
5151
def run(instance, evaluator)
5252
socket_path = evaluator.ipc_socket_path
5353
timeout = evaluator.ipc_connection_timeout
@@ -88,7 +88,7 @@ def run(instance, evaluator)
8888
end
8989

9090
module IPCEnvironment
91-
include Async::Service::ManagedEnvironment
91+
include Async::Service::Managed::Environment
9292

9393
def ipc_socket_path
9494
File.expand_path("service.ipc", Dir.pwd)

examples/supervisor/service.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# Copyright, 2024-2025, by Samuel Williams.
66

77
require "async/container/supervisor"
8-
require "async/service/managed_service"
9-
require "async/service/managed_environment"
8+
require "async/service/managed/service"
9+
require "async/service/managed/environment"
1010

11-
class MemoryUsageService < Async::Service::ManagedService
11+
class MemoryUsageService < Async::Service::Managed::Service
1212
def run(instance, evaluator)
1313
things = []
1414

@@ -30,7 +30,7 @@ def run(instance, evaluator)
3030
end
3131

3232
service "memory-usage" do
33-
include Async::Service::ManagedEnvironment
33+
include Async::Service::Managed::Environment
3434

3535
service_class MemoryUsageService
3636

guides/best-practices/readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Place environments in `lib/my_library/environment/`:
6161
module MyLibrary
6262
module Environment
6363
module WebEnvironment
64-
include Async::Service::ManagedEnvironment
64+
include Async::Service::Managed::Environment
6565

6666
def service_class
6767
MyLibrary::Service::WebService
@@ -87,7 +87,7 @@ Place services in `lib/my_library/service/`:
8787
# lib/my_library/service/web_service.rb
8888
module MyLibrary
8989
module Service
90-
class WebService < Async::Service::ManagedService
90+
class WebService < Async::Service::Managed::Service
9191
private def format_title(evaluator, server)
9292
if server&.respond_to?(:connection_count)
9393
"#{self.name} [#{evaluator.host}:#{evaluator.port}] (#{server.connection_count} connections)"
@@ -114,7 +114,7 @@ end
114114

115115
### Use `Managed::Environment` for Services
116116

117-
Include {ruby Async::Service::ManagedEnvironment} for services that need robust lifecycle management using {ruby Async::Service::ManagedService}:
117+
Include {ruby Async::Service::Managed::Environment} for services that need robust lifecycle management using {ruby Async::Service::Managed::Service}:
118118

119119
```ruby
120120
module WebEnvironment
@@ -201,7 +201,7 @@ end
201201

202202
### Use `Managed::Service` as Base Class
203203

204-
Prefer `Async::Service::ManagedService` over `Generic` for most services:
204+
Prefer `Async::Service::Managed::Service` over `Generic` for most services:
205205

206206
```ruby
207207
class WebService < Async::Service::ManagedService
@@ -243,7 +243,7 @@ module WebEnvironment
243243
end
244244
```
245245

246-
The `startup_timeout` ensures processes that hang during startup are detected, while `health_check_timeout` monitors processes after they've become ready. `ManagedService` automatically sends `status!` messages during startup to keep the health check clock resetting until the service is ready.
246+
The `startup_timeout` ensures processes that hang during startup are detected, while `health_check_timeout` monitors processes after they've become ready. `Managed::Service` automatically sends `status!` messages during startup to keep the health check clock resetting until the service is ready.
247247

248248
### Implement Meaningful Process Titles
249249

guides/deployment/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require "async/http"
1414
require "async/service/managed_service"
1515
require "async/service/managed_environment"
1616

17-
class WebService < Async::Service::ManagedService
17+
class WebService < Async::Service::Managed::Service
1818
def start
1919
super
2020
@endpoint = @evaluator.endpoint
@@ -40,7 +40,7 @@ class WebService < Async::Service::ManagedService
4040
end
4141

4242
module WebEnvironment
43-
include Async::Service::ManagedEnvironment
43+
include Async::Service::Managed::Environment
4444

4545
def endpoint
4646
Async::HTTP::Endpoint.parse("http://0.0.0.0:3000")

guides/service-architecture/readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ end
262262

263263
### Health Checking
264264

265-
For services using `Async::Service::ManagedService`, health checking is handled automatically. The service sends `status!` messages during startup to prevent premature health check timeouts, then transitions to sending `ready!` messages once the service is actually ready.
265+
For services using `Async::Service::Managed::Service`, health checking is handled automatically. The service sends `status!` messages during startup to prevent premature health check timeouts, then transitions to sending `ready!` messages once the service is actually ready.
266266

267267
For services extending `Generic`, you can set up health checking manually:
268268

@@ -302,7 +302,7 @@ You can configure these timeouts via `container_options`:
302302

303303
```ruby
304304
module WebEnvironment
305-
include Async::Service::ManagedEnvironment
305+
include Async::Service::Managed::Environment
306306

307307
def container_options
308308
super.merge(
@@ -313,7 +313,7 @@ module WebEnvironment
313313
end
314314
```
315315

316-
Note: `Async::Service::ManagedService` automatically handles health checking, container options, and process title formatting, so you typically don't need to set this up manually.
316+
Note: `Async::Service::Managed::Service` automatically handles health checking, container options, and process title formatting, so you typically don't need to set this up manually.
317317

318318
## How They Work Together
319319

@@ -469,7 +469,7 @@ Create reusable configuration modules:
469469

470470
```ruby
471471
module ManagedEnvironment
472-
include Async::Service::ManagedEnvironment
472+
include Async::Service::Managed::Environment
473473

474474
def count
475475
4
Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,16 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2025, by Samuel Williams.
4+
# Copyright, 2024-2025, by Samuel Williams.
5+
6+
# Compatibility shim for Async::Service::HealthChecker
7+
# Use Async::Service::Managed::HealthChecker instead
8+
require_relative "managed/health_checker"
59

610
module Async
711
module Service
8-
# A health checker for managed services.
9-
module HealthChecker
10-
# Start the health checker.
11-
#
12-
# If a timeout is specified, a transient child task will be scheduled, which will yield the instance if a block is given, then mark the instance as ready, and finally sleep for half the health check duration (so that we guarantee that the health check runs in time).
13-
#
14-
# If a timeout is not specified, the health checker will yield the instance immediately and then mark the instance as ready.
15-
#
16-
# @parameter instance [Object] The service instance to check.
17-
# @parameter timeout [Numeric] The timeout duration for the health check.
18-
# @parameter parent [Async::Task] The parent task to run the health checker in.
19-
# @yields {|instance| ...} If a block is given, it will be called with the service instance at least once.
20-
def health_checker(instance, timeout = @evaluator.health_check_timeout, parent: Async::Task.current, &block)
21-
if timeout
22-
parent.async(transient: true) do
23-
while true
24-
if block_given?
25-
yield(instance)
26-
end
27-
28-
# We deliberately create a fiber here, to confirm that fiber creation is working.
29-
# If something has gone wrong with fiber allocation, we will crash here, and that's okay.
30-
Fiber.new do
31-
instance.healthy!
32-
end.resume
33-
34-
sleep(timeout / 2.0)
35-
end
36-
end
37-
else
38-
if block_given?
39-
yield(instance)
40-
end
41-
42-
instance.healthy!
43-
end
44-
end
45-
end
12+
# @deprecated Use {Managed::HealthChecker} instead.
13+
HealthChecker = Managed::HealthChecker
4614
end
4715
end
4816

0 commit comments

Comments
 (0)