|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | # 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" |
5 | 9 |
|
6 | 10 | module Async |
7 | 11 | 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 |
46 | 14 | end |
47 | 15 | end |
48 | 16 |
|
0 commit comments