async-service-supervisor 0.10.1 → 0.11.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: 1a442d07a68cfadfaf0a5a1e15e5ec7b0936580c74e6cc49b30997816b0e62b2
4
- data.tar.gz: d275c9154c1e9cd9a8c37bee158b1121ebdbb0d78e4b86b2bead32f32d55e1f1
3
+ metadata.gz: 4c3d5a7d855b76ef324f1f7b30e7a4dc45155150b84bd1f9725511de1c0e689f
4
+ data.tar.gz: 7baf1593e4ddcfde54579aa00586fe2b5eff4fe3a6ed81da89a37d4da4831f3b
5
5
  SHA512:
6
- metadata.gz: b47eb23e854c83816211f4385a6c88a8ace3b5e71512469a73c63968a2569c1288bb2cc68a6e0c2f0e874405477906d12839eefc07d83123fa5c6cf48e3c904e
7
- data.tar.gz: f1831a15940111dce4550208f6d0047e21bd6fff32015f98c1aee44c650ea41fcf540707e509b84e7146ff2f3e18a08503c787699311fc0dd36a2a0806fadc7d
6
+ metadata.gz: 7c5ce6b4f95785d1fe6c90e704217f5d15a04cd7a8b5cd73ca8071a7359639bc0e2637bced931a5632bb6151b022cc3ce5bdf59e264c31dfe5ebc2705c8fb586
7
+ data.tar.gz: 9efb2ce0bd7214756f52bc333590b44d2c634296cf9dbd5ec328b8d6d5b8c3188f6b245719e2c925a335cf2016b9c33e0d10b2cb8b9ad020e1ee7108433cbce2
checksums.yaml.gz.sig CHANGED
Binary file
data/context/migration.md CHANGED
@@ -309,3 +309,9 @@ The new approach provides:
309
309
  - Simpler ID management.
310
310
  - Better controller-based API.
311
311
  - More explicit worker lifecycle management.
312
+
313
+ ### Connection State Handling
314
+
315
+ State has moved from `connection.state` to `supervisor_controller.state`. Monitors receive `supervisor_controller` objects instead of `connection` objects, and access state via `supervisor_controller.state[:name]` instead of `connection.state[:name]`.
316
+
317
+ By default, the `Supervised` module automatically includes the service name in state via `supervisor_worker_state`. Override `supervisor_worker_state` in your service environment to customize the state.
@@ -24,10 +24,16 @@ module Async
24
24
  ::IO::Endpoint.unix(supervisor_ipc_path)
25
25
  end
26
26
 
27
+ # The state to associate with the supervised worker.
28
+ # @returns [Hash]
29
+ def supervisor_worker_state
30
+ {name: self.name}
31
+ end
32
+
27
33
  # The supervised worker for the current process.
28
34
  # @returns [Worker] The worker client.
29
35
  def supervisor_worker
30
- Worker.new(process_id: Process.pid, endpoint: supervisor_endpoint)
36
+ Worker.new(process_id: Process.pid, endpoint: supervisor_endpoint, state: self.supervisor_worker_state)
31
37
  end
32
38
 
33
39
  # Create a supervised worker for the given instance.
@@ -19,6 +19,7 @@ module Async
19
19
  @id = nil
20
20
  @process_id = nil
21
21
  @worker = nil
22
+ @state = {}
22
23
  end
23
24
 
24
25
  # @attribute [Server] The server instance.
@@ -36,6 +37,9 @@ module Async
36
37
  # @attribute [Proxy] The proxy to the worker controller.
37
38
  attr :worker
38
39
 
40
+ # @attribute [Hash] State associated with this worker connection (e.g., service name).
41
+ attr_accessor :state
42
+
39
43
  # Register a worker connection with the supervisor.
40
44
  #
41
45
  # Allocates a unique sequential ID, stores the worker controller proxy,
@@ -43,13 +47,15 @@ module Async
43
47
  #
44
48
  # @parameter worker [Proxy] The proxy to the worker controller.
45
49
  # @parameter process_id [Integer] The process ID of the worker.
50
+ # @parameter state [Hash] Optional state to associate with this worker (e.g., service name).
46
51
  # @returns [Integer] The connection ID assigned to the worker.
47
- def register(worker, process_id:)
52
+ def register(worker, process_id:, state: {})
48
53
  raise RuntimeError, "Already registered" if @id
49
54
 
50
55
  @id = @server.next_id
51
56
  @process_id = process_id
52
57
  @worker = worker
58
+ @state.merge!(state)
53
59
 
54
60
  @server.add(self)
55
61
 
@@ -9,7 +9,7 @@ module Async
9
9
  module Service
10
10
  # @namespace
11
11
  module Supervisor
12
- VERSION = "0.10.1"
12
+ VERSION = "0.11.0"
13
13
  end
14
14
  end
15
15
  end
@@ -25,11 +25,13 @@ module Async
25
25
  #
26
26
  # @parameter process_id [Integer] The process ID to register with the supervisor.
27
27
  # @parameter endpoint [IO::Endpoint] The supervisor endpoint to connect to.
28
- def initialize(process_id: Process.pid, endpoint: Supervisor.endpoint)
28
+ # @parameter state [Hash] Optional state to associate with this worker (e.g., service name).
29
+ def initialize(process_id: Process.pid, endpoint: Supervisor.endpoint, state: {})
29
30
  super(endpoint: endpoint)
30
31
 
31
32
  @id = nil
32
33
  @process_id = process_id
34
+ @state = state
33
35
  end
34
36
 
35
37
  # @attribute [Integer] The ID assigned by the supervisor.
@@ -38,6 +40,9 @@ module Async
38
40
  # @attribute [Integer] The process ID of the worker.
39
41
  attr :process_id
40
42
 
43
+ # @attribute [Hash] State associated with this worker (e.g., service name).
44
+ attr_accessor :state
45
+
41
46
  protected def connected!(connection)
42
47
  super
43
48
 
@@ -49,10 +54,9 @@ module Async
49
54
  # The supervisor allocates a unique ID and returns it
50
55
  # This is a synchronous RPC call that will complete before returning
51
56
  supervisor = connection[:supervisor]
52
- @id = supervisor.register(worker_proxy, process_id: @process_id)
57
+ @id = supervisor.register(worker_proxy, process_id: @process_id, state: @state)
53
58
  end
54
59
  end
55
60
  end
56
61
  end
57
62
  end
58
-
data/readme.md CHANGED
@@ -28,6 +28,12 @@ Please see the [project documentation](https://socketry.github.io/async-service-
28
28
 
29
29
  Please see the [project releases](https://socketry.github.io/async-service-supervisor/releases/index) for all releases.
30
30
 
31
+ ### v0.11.0
32
+
33
+ - Add `state` attribute to `SupervisorController` to store per-worker metadata (e.g., service name).
34
+ - Add `state` parameter to `Worker#initialize` to allow workers to provide state during registration.
35
+ - State is now accessible via `supervisor_controller.state` instead of `connection.state` (as it was in `Async::Container::Supervisor`).
36
+
31
37
  ### v0.10.0
32
38
 
33
39
  - Serialize `register`/`remove` and `check!` operations in `MemoryMonitor` to prevent race conditions.
@@ -71,10 +77,6 @@ Please see the [project releases](https://socketry.github.io/async-service-super
71
77
 
72
78
  - Add `async:container:supervisor:reload` command to restart the container (blue/green deployment).
73
79
 
74
- ### v0.1.0
75
-
76
- - Initial implementation.
77
-
78
80
  ## Contributing
79
81
 
80
82
  We welcome contributions to this project.
data/releases.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Releases
2
2
 
3
+ ## v0.11.0
4
+
5
+ - Add `state` attribute to `SupervisorController` to store per-worker metadata (e.g., service name).
6
+ - Add `state` parameter to `Worker#initialize` to allow workers to provide state during registration.
7
+ - State is now accessible via `supervisor_controller.state` instead of `connection.state` (as it was in `Async::Container::Supervisor`).
8
+
3
9
  ## v0.10.0
4
10
 
5
11
  - Serialize `register`/`remove` and `check!` operations in `MemoryMonitor` to prevent race conditions.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-service-supervisor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file