You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/best-practices/readme.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -208,6 +208,7 @@ class WebService < Async::Service::ManagedService
208
208
# Managed::Service automatically handles:
209
209
# - Container setup with proper options.
210
210
# - Health checking with process title updates.
211
+
# - Status messages during startup to prevent premature timeouts.
211
212
# - Preloading of scripts before startup.
212
213
213
214
privatedefformat_title(evaluator, server)
@@ -222,6 +223,28 @@ class WebService < Async::Service::ManagedService
222
223
end
223
224
```
224
225
226
+
### Configure Timeouts for Slow-Starting Services
227
+
228
+
If your service takes a long time to start up (e.g., loading large datasets, connecting to external services), configure appropriate timeouts:
229
+
230
+
```ruby
231
+
moduleWebEnvironment
232
+
includeAsync::Service::ManagedEnvironment
233
+
234
+
# Allow 2 minutes for startup.
235
+
defstartup_timeout
236
+
120
237
+
end
238
+
239
+
# Require health checks every 30 seconds.
240
+
defhealth_check_timeout
241
+
30
242
+
end
243
+
end
244
+
```
245
+
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.
247
+
225
248
### Implement Meaningful Process Titles
226
249
227
250
Use the `format_title` method to provide dynamic process information:
Copy file name to clipboardExpand all lines: guides/service-architecture/readme.md
+31-2Lines changed: 31 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -262,20 +262,25 @@ end
262
262
263
263
### Health Checking
264
264
265
-
For services using `Async::Service::ManagedService`, health checking is handled automatically. For services extending `GenericService`, you can set up health checking manually:
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.
266
+
267
+
For services extending `GenericService`, you can set up health checking manually:
#Set up health checking, if a timeout was specified:
283
+
#Once ready, set up health checking:
279
284
health_checker(instance, health_check_timeout) do
280
285
instance.name ="#{self.name}: #{current_status}"
281
286
end
@@ -284,6 +289,30 @@ def setup(container)
284
289
end
285
290
```
286
291
292
+
#### Startup Timeout vs Health Check Timeout
293
+
294
+
The container supports two separate timeout mechanisms:
295
+
296
+
-**`startup_timeout`**: Maximum time a process can take to become ready (call `ready!`) before being terminated. This detects processes that hang during startup and never become ready.
297
+
-**`health_check_timeout`**: Maximum time between health check messages after the process has become ready. This detects processes that stop responding after they've started.
298
+
299
+
Both timeouts use a single clock that starts when the process starts. The clock resets when the process becomes ready, transitioning from startup timeout monitoring to health check timeout monitoring.
300
+
301
+
You can configure these timeouts via `container_options`:
302
+
303
+
```ruby
304
+
moduleWebEnvironment
305
+
includeAsync::Service::ManagedEnvironment
306
+
307
+
defcontainer_options
308
+
super.merge(
309
+
startup_timeout:60, # Allow up to 60 seconds for startup.
310
+
health_check_timeout:30# Require health checks every 30 seconds after ready.
311
+
)
312
+
end
313
+
end
314
+
```
315
+
287
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.
0 commit comments