async-container 0.22.0 → 0.23.1

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: 97b99976b04ac8d7725349a23176ff2ca94643a4e95c96b6ab566a957be437d7
4
- data.tar.gz: ec7aa60548299430c13b14d6abee5df28ec383b48dafb7e60432574bd07dd6fb
3
+ metadata.gz: 45498b6ccc16a193e4562b68437909aa982613b11a3959608de293246edc1f31
4
+ data.tar.gz: fa3b269ba5e24b5500fb05409a6c5835127adf8cbda92bff54cc661358e10921
5
5
  SHA512:
6
- metadata.gz: 8b44d6496b6b9fa16bc288ecc66f0ba0645a0b3301d2a32bf53fbf27f993803cba38b6da9208baa3ef6c14fececb9da65cda6ab8d8ae403aa04c666c4077c978
7
- data.tar.gz: 61d79bd5e62d8b406ffe88aae129918b5ab7c3de779847e8295e6dff867fdc58573c68e7df7bee585b9b204c6150dd98bc82fc424c8c6643df7eedd9dbd11f7c
6
+ metadata.gz: 4481f2950cfacc074c010419ce3afaa785435df9066b072e4d514a7ea3319fd930242afb8ef0f3e40020d7674209d792a4a42059f1f44cdc3270669bca52ef7b
7
+ data.tar.gz: '018f892e9b7b9cd7703ce0b9e15a8eb689804563b8d691a676f51a0ad79b0d78681d34bca2c63da9e508c8b48dc617cb03dde3911af5271e42997a334dcf06bd'
checksums.yaml.gz.sig CHANGED
Binary file
@@ -149,7 +149,7 @@ module Async
149
149
  old_container&.stop(@graceful_stop)
150
150
  end
151
151
 
152
- @notify&.ready!
152
+ @notify&.ready!(size: @container.size)
153
153
  ensure
154
154
  # If we are leaving this function with an exception, try to kill the container:
155
155
  container&.stop(false)
@@ -185,7 +185,7 @@ module Async
185
185
 
186
186
  # Enter the controller run loop, trapping `SIGINT` and `SIGTERM`.
187
187
  def run
188
- @notify&.status!("Initializing...")
188
+ @notify&.status!("Initializing controller...")
189
189
 
190
190
  with_signal_handlers do
191
191
  self.start
@@ -51,6 +51,11 @@ module Async
51
51
  # @attribute [Group] The group of running children instances.
52
52
  attr :group
53
53
 
54
+ # @returns [Integer] The number of running children instances.
55
+ def size
56
+ @group.size
57
+ end
58
+
54
59
  # @attribute [Hash(Child, Hash)] The state of each child instance.
55
60
  attr :state
56
61
 
@@ -32,6 +32,11 @@ module Async
32
32
  # @attribute [Hash(IO, Fiber)] the running tasks, indexed by IO.
33
33
  attr :running
34
34
 
35
+ # @returns [Integer] The number of running processes.
36
+ def size
37
+ @running.size
38
+ end
39
+
35
40
  # Whether the group contains any running processes.
36
41
  # @returns [Boolean]
37
42
  def running?
@@ -175,7 +180,8 @@ module Async
175
180
  protected
176
181
 
177
182
  def wait_for_children(duration = nil)
178
- Console.debug(self, "Waiting for children...", duration: duration, running: @running)
183
+ # This log is a big noisy and doesn't really provide a lot of useful information.
184
+ # Console.debug(self, "Waiting for children...", duration: duration, running: @running)
179
185
 
180
186
  if !@running.empty?
181
187
  # Maybe consider using a proper event loop here:
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
5
+
6
+ require_relative "client"
7
+ require "socket"
8
+
9
+ module Async
10
+ module Container
11
+ module Notify
12
+ class Log < Client
13
+ # The name of the environment variable which contains the path to the notification socket.
14
+ NOTIFY_LOG = "NOTIFY_LOG"
15
+
16
+ # Open a notification client attached to the current {NOTIFY_LOG} if possible.
17
+ def self.open!(environment = ENV)
18
+ if path = environment.delete(NOTIFY_LOG)
19
+ self.new(path)
20
+ end
21
+ end
22
+
23
+ # Initialize the notification client.
24
+ # @parameter path [String] The path to the UNIX socket used for sending messages to the process manager.
25
+ def initialize(path)
26
+ @path = path
27
+ end
28
+
29
+ # @attribute [String] The path to the UNIX socket used for sending messages to the controller.
30
+ attr :path
31
+
32
+ # Send the given message.
33
+ # @parameter message [Hash]
34
+ def send(**message)
35
+ data = JSON.dump(message)
36
+
37
+ File.open(@path, "a") do |file|
38
+ file.puts(data)
39
+ end
40
+ end
41
+
42
+ # Send the specified error.
43
+ # `sd_notify` requires an `errno` key, which defaults to `-1` to indicate a generic error.
44
+ def error!(text, **message)
45
+ message[:errno] ||= -1
46
+
47
+ super
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -5,6 +5,7 @@
5
5
  # Copyright, 2020, by Olle Jonsson.
6
6
 
7
7
  require "tmpdir"
8
+ require "socket"
8
9
  require "securerandom"
9
10
 
10
11
  module Async
@@ -6,6 +6,7 @@
6
6
  require_relative "notify/pipe"
7
7
  require_relative "notify/socket"
8
8
  require_relative "notify/console"
9
+ require_relative "notify/log"
9
10
 
10
11
  module Async
11
12
  module Container
@@ -18,6 +19,7 @@ module Async
18
19
  @client ||= (
19
20
  Pipe.open! ||
20
21
  Socket.open! ||
22
+ Log.open! ||
21
23
  Console.open!
22
24
  )
23
25
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Container
8
- VERSION = "0.22.0"
8
+ VERSION = "0.23.1"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -22,6 +22,10 @@ Please see the [project documentation](https://socketry.github.io/async-containe
22
22
 
23
23
  Please see the [project releases](https://socketry.github.io/async-container/releases/index) for all releases.
24
24
 
25
+ ### v0.23.0
26
+
27
+ - [Add support for `NOTIFY_LOG` for Kubernetes readiness probes.](https://socketry.github.io/async-container/releases/index#add-support-for-notify_log-for-kubernetes-readiness-probes.)
28
+
25
29
  ### v0.21.0
26
30
 
27
31
  - Use `SIGKILL`/`Thread#kill` when the health check fails. In some cases, `SIGTERM` may not be sufficient to terminate a process because the signal can be ignored or the process may be in an uninterruptible state.
data/releases.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Releases
2
2
 
3
+ ## v0.23.0
4
+
5
+ ### Add support for `NOTIFY_LOG` for Kubernetes readiness probes.
6
+
7
+ You may specify a `NOTIFY_LOG` environment variable to enable readiness logging to a log file. This can be used for Kubernetes readiness probes, e.g.
8
+
9
+ ``` yaml
10
+ containers:
11
+ - name: falcon
12
+ env:
13
+ - name: NOTIFY_LOG
14
+ value: "/tmp/notify.log"
15
+ command: ["falcon", "host"]
16
+ readinessProbe:
17
+ exec:
18
+ command: ["sh", "-c", "grep -q '\"ready\":true' /tmp/notify.log"]
19
+ initialDelaySeconds: 5
20
+ periodSeconds: 5
21
+ failureThreshold: 12
22
+ ```
23
+
3
24
  ## v0.21.0
4
25
 
5
26
  - Use `SIGKILL`/`Thread#kill` when the health check fails. In some cases, `SIGTERM` may not be sufficient to terminate a process because the signal can be ignored or the process may be in an uninterruptible state.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-container
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -40,7 +40,7 @@ cert_chain:
40
40
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
41
41
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
42
42
  -----END CERTIFICATE-----
43
- date: 2025-02-26 00:00:00.000000000 Z
43
+ date: 2025-02-27 00:00:00.000000000 Z
44
44
  dependencies:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: async
@@ -73,6 +73,7 @@ files:
73
73
  - lib/async/container/notify.rb
74
74
  - lib/async/container/notify/client.rb
75
75
  - lib/async/container/notify/console.rb
76
+ - lib/async/container/notify/log.rb
76
77
  - lib/async/container/notify/pipe.rb
77
78
  - lib/async/container/notify/server.rb
78
79
  - lib/async/container/notify/socket.rb
metadata.gz.sig CHANGED
Binary file