async-service 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de59afc9bb1a297f08d89797f5cc1cab814aadb6fd867773a70a3c2b83bcf1d7
4
- data.tar.gz: 07c8402c361ae967fd593616d1777367118687fa490b9bb8e5cb5e64003280c0
3
+ metadata.gz: 5f7f1e1833ae119be22f91c6c84073871863a49269b3173a9ed0506dbdb7afc3
4
+ data.tar.gz: a05e566aa7668b42991189b7bcea2f8e9e298a4a51545880e965e82256ac7d8e
5
5
  SHA512:
6
- metadata.gz: 777190197a4272ce2f8c726abdbf1b018e46af424ca68d9fbfa4eba8490912e3c9cbb9579490743bbddf384a3b4fa2159f38ec9d58c013badd9ce4642f9bfb68
7
- data.tar.gz: 5976d4d560ddcb71e781bdd1ec9a304f7851ed3cb76f1f1d82fb590765fd4137cd463afabb4da78abead51f328ce5d55cd3b45d272056fa765be086c1531c835
6
+ metadata.gz: 64b72fff461e46bf290c993b0fbe2ca03a7014f4cecbf0af35bceb32e5303626a62bfdeb4f2bf2fe78ae07c763939ad5830e3613881af89d9b5f80e123fa20fb
7
+ data.tar.gz: 6e64b02a88d0bf6b07fe228cf125c1b6864f9f29d589e2c828b7bd6733a154b2c40f4ac7e83b4f715d28281d2284a331e13669925f81ff0bed1025df63d0aa76
checksums.yaml.gz.sig CHANGED
Binary file
@@ -11,12 +11,19 @@ module Async
11
11
  # Designed to be invoked within an {Async::Controller::Container}.
12
12
  class Generic
13
13
  # Convert the given environment into a service if possible.
14
+ #
15
+ # If the evaluator responds to `make_service`, it is called with the environment and its return value is used as the service. This allows environments to compose child environments and return a concrete service without a dedicated service class.
16
+ #
17
+ # Otherwise, the evaluator's `service_class` is instantiated with the environment and evaluator as arguments.
18
+ #
14
19
  # @parameter environment [Environment] The environment to use to construct the service.
15
- # @returns [Generic | Nil] The constructed service if the environment specifies a service class.
20
+ # @returns [Generic | Nil] The constructed service if the environment specifies a service class or make_service.
16
21
  def self.wrap(environment)
17
22
  evaluator = environment.evaluator
18
23
 
19
- if evaluator.key?(:service_class)
24
+ if evaluator.respond_to?(:make_service)
25
+ return evaluator.make_service(environment)
26
+ elsif evaluator.key?(:service_class)
20
27
  if service_class = evaluator.service_class
21
28
  return service_class.new(environment, evaluator)
22
29
  end
@@ -10,32 +10,28 @@ module Async
10
10
  module HealthChecker
11
11
  # Start the health checker.
12
12
  #
13
- # 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
+ # If a timeout is specified, a transient child task will be scheduled which will mark the instance as healthy, sleep for half the health check duration (so that we guarantee that the health check runs in time), and then yield the instance if a block is given. This repeats indefinitely.
14
14
  #
15
- # If a timeout is not specified, the health checker will yield the instance immediately and then mark the instance as ready.
15
+ # If a timeout is not specified, the instance is marked as healthy immediately and no task is created. Any block given is ignored.
16
16
  #
17
17
  # @parameter instance [Object] The service instance to check.
18
18
  # @parameter timeout [Numeric] The timeout duration for the health check.
19
19
  # @parameter parent [Async::Task] The parent task to run the health checker in.
20
- # @yields {|instance| ...} If a block is given, it will be called with the service instance at least once.
20
+ # @yields {|instance| ...} If a block is given and a timeout is specified, it will be called with the service instance after each sleep interval.
21
21
  def health_checker(instance, timeout = @evaluator.health_check_timeout, parent: Async::Task.current, &block)
22
22
  if timeout
23
23
  parent.async(transient: true) do
24
24
  while true
25
- if block_given?
26
- yield(instance)
27
- end
28
-
29
25
  instance.healthy!
30
26
 
31
27
  sleep(timeout / 2.0)
28
+
29
+ if block_given?
30
+ yield(instance)
31
+ end
32
32
  end
33
33
  end
34
34
  else
35
- if block_given?
36
- yield(instance)
37
- end
38
-
39
35
  instance.healthy!
40
36
  end
41
37
  end
@@ -93,6 +93,7 @@ module Async
93
93
  evaluator = self.environment.evaluator
94
94
  server = nil
95
95
 
96
+ # If a health check timeout is configured, this block runs periodically to refresh the process title. Without a timeout there is no periodic timer, so the block is never called — the one-shot assignment below handles that case.
96
97
  health_checker(instance, health_check_timeout) do
97
98
  if server
98
99
  instance.name = format_title(evaluator, server)
@@ -105,6 +106,8 @@ module Async
105
106
 
106
107
  instance.status!("Running...")
107
108
  server = run(instance, evaluator)
109
+ # Set the process title immediately once the server is available:
110
+ instance.name = format_title(evaluator, server)
108
111
  emit_running(instance, clock)
109
112
 
110
113
  instance.ready!
@@ -7,6 +7,6 @@
7
7
  module Async
8
8
  # @namespace
9
9
  module Service
10
- VERSION = "0.21.0"
10
+ VERSION = "0.23.0"
11
11
  end
12
12
  end
data/readme.md CHANGED
@@ -31,6 +31,18 @@ Please see the [project documentation](https://socketry.github.io/async-service/
31
31
 
32
32
  Please see the [project releases](https://socketry.github.io/async-service/releases/index) for all releases.
33
33
 
34
+ ### v0.23.0
35
+
36
+ - `Async::Service::Generic.wrap` now checks for a `make_service(environment)` method on the evaluator before falling back to `service_class`. This allows environments to compose child environments and return a fully-constructed service without introducing a dedicated service class.
37
+
38
+ ### v0.22.0
39
+
40
+ - Ensure process title is updated immediately after server starts in `Managed::Service`.
41
+
42
+ ### v0.21.0
43
+
44
+ - Add missing bake files.
45
+
34
46
  ### v0.20.1
35
47
 
36
48
  - Use `container.stopping?` in policy to prevent redundant stop calls during graceful shutdown.
@@ -70,19 +82,6 @@ Please see the [project releases](https://socketry.github.io/async-service/relea
70
82
  - Renamed `Async::Service::Managed::Service` -\> `Async::Service::ManagedService`.
71
83
  - Renamed `Async::Service::Managed::Environment` -\> `Async::Service::ManagedEnvironment`.
72
84
 
73
- ### v0.15.1
74
-
75
- - `Managed::Service` should run within `Async do ... end`.
76
-
77
- ### v0.15.0
78
-
79
- - Rename `ContainerEnvironment` and `ContainerService` to `Managed::Environment` and `Managed::Service` respectively.
80
- - Health check uses `Fiber.new{instance.ready!}.resume` to confirm fiber allocation is working.
81
-
82
- ### v0.14.4
83
-
84
- - Use `String::Format` gem for formatting.
85
-
86
85
  ## Contributing
87
86
 
88
87
  We welcome contributions to this project.
data/releases.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Releases
2
2
 
3
+ ## v0.23.0
4
+
5
+ - `Async::Service::Generic.wrap` now checks for a `make_service(environment)` method on the evaluator before falling back to `service_class`. This allows environments to compose child environments and return a fully-constructed service without introducing a dedicated service class.
6
+
7
+ ## v0.22.0
8
+
9
+ - Ensure process title is updated immediately after server starts in `Managed::Service`.
10
+
11
+ ## v0.21.0
12
+
13
+ - Add missing bake files.
14
+
3
15
  ## v0.20.1
4
16
 
5
17
  - Use `container.stopping?` in policy to prevent redundant stop calls during graceful shutdown.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
- rubygems_version: 4.0.3
136
+ rubygems_version: 4.0.6
137
137
  specification_version: 4
138
138
  summary: A service layer for Async.
139
139
  test_files: []
metadata.gz.sig CHANGED
Binary file