async-container 0.35.1 → 0.37.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: 293edf1aac3945b8751879fe8b8180e7fb9bcc769f5b1bea315687f19d33ea11
4
- data.tar.gz: 60699b17d30ce273a236b0728246a10fb7bb47691d3f2b3827a0bc08c51fa097
3
+ metadata.gz: 62299eb75e389a8fcf1f7b179cdbc7803a0ecebc4fe41fb6e1f1023b702b5573
4
+ data.tar.gz: d13e79527be255c01311c07979eaed4ca6c22d18c36b51a2ea2644617975562c
5
5
  SHA512:
6
- metadata.gz: 2febcb62a2cdce3e43e92fa0d39a943bb92ade5ef0af9401810853fdb27bca98805a75d029926bbf61de0a130da293169fc9533d091d74cd11c0d01f0ee5c296
7
- data.tar.gz: 909529d757ada40f2501f96455df4f4ecad4a739365b52ef35ef77ae449c9b6869351a73cb28e0c335ef0793fed2c35656a9e6218e1b79da73fec5d4a8b09e9c
6
+ metadata.gz: d819e162498afd6c99125e525145fe981ceccb6d6bed77da0d01ea586f91052a24666bcd37676d66662d52637db0827536d61669e4ffee816de57d32ba621a56
7
+ data.tar.gz: a01f2d1a4e22ac3152392bbbdc42475ab333d1cc4605d3fb20711f495e889a2fd91de77d1bdfed580267d5d49d932b74f1b491a584551bd79b55a4cf285b474e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -12,6 +12,18 @@ require_relative "policy"
12
12
 
13
13
  module Async
14
14
  module Container
15
+ # The default graceful stop policy for controllers.
16
+ GRACEFUL_STOP = ENV.fetch("ASYNC_CONTAINER_GRACEFUL_STOP", "true").then do |value|
17
+ case value
18
+ when "true"
19
+ true # Default timeout for graceful termination.
20
+ when "false"
21
+ false # Immediately kill the processes.
22
+ else
23
+ value.to_f
24
+ end
25
+ end
26
+
15
27
  # Manages the life-cycle of one or more containers in order to support a persistent system.
16
28
  # e.g. a web server, job server or some other long running system.
17
29
  class Controller
@@ -23,7 +35,7 @@ module Async
23
35
 
24
36
  # Initialize the controller.
25
37
  # @parameter notify [Notify::Client] A client used for process readiness notifications.
26
- def initialize(notify: Notify.open!, container_class: Container, graceful_stop: true)
38
+ def initialize(notify: Notify.open!, container_class: Container, graceful_stop: GRACEFUL_STOP)
27
39
  @notify = notify
28
40
  @container_class = container_class
29
41
  @graceful_stop = graceful_stop
@@ -101,23 +101,25 @@ module Async
101
101
  def self.fork(**options)
102
102
  # $stderr.puts fork: caller
103
103
  self.new(**options) do |process|
104
- ::Process.fork do
105
- # We use `Thread.current.raise(...)` so that exceptions are filtered through `Thread.handle_interrupt` correctly.
106
- Signal.trap(:INT){::Thread.current.raise(Interrupt)}
107
- Signal.trap(:TERM){::Thread.current.raise(Interrupt)} # Same as SIGINT.
108
- Signal.trap(:HUP){::Thread.current.raise(Restart)}
109
-
110
- # This could be a configuration option:
111
- ::Thread.handle_interrupt(SignalException => :immediate) do
112
- yield Instance.for(process)
113
- rescue Interrupt
114
- # Graceful exit.
115
- rescue Exception => error
116
- Console.error(self, error)
104
+ ::Thread.new do
105
+ ::Process.fork do
106
+ # We use `Thread.current.raise(...)` so that exceptions are filtered through `Thread.handle_interrupt` correctly.
107
+ Signal.trap(:INT){::Thread.current.raise(Interrupt)}
108
+ Signal.trap(:TERM){::Thread.current.raise(Interrupt)} # Same as SIGINT.
109
+ Signal.trap(:HUP){::Thread.current.raise(Restart)}
117
110
 
118
- exit!(1)
111
+ # This could be a configuration option:
112
+ ::Thread.handle_interrupt(SignalException => :immediate) do
113
+ yield Instance.for(process)
114
+ rescue Interrupt
115
+ # Graceful exit.
116
+ rescue Exception => error
117
+ Console.error(self, error)
118
+
119
+ exit!(1)
120
+ end
119
121
  end
120
- end
122
+ end.value
121
123
  end
122
124
  end
123
125
 
@@ -10,19 +10,7 @@ require_relative "error"
10
10
 
11
11
  module Async
12
12
  module Container
13
- # The default timeout for terminating processes, before escalating to killing.
14
- GRACEFUL_TIMEOUT = ENV.fetch("ASYNC_CONTAINER_GRACEFUL_TIMEOUT", "true").then do |value|
15
- case value
16
- when "true"
17
- true # Default timeout for graceful termination.
18
- when "false"
19
- false # Immediately kill the processes.
20
- else
21
- value.to_f
22
- end
23
- end
24
-
25
- # The default timeout for graceful termination.
13
+ # The default timeout for graceful termination, used when the `graceful` argument is true.
26
14
  DEFAULT_GRACEFUL_TIMEOUT = 10.0
27
15
 
28
16
  # Manages a group of running processes.
@@ -163,7 +151,7 @@ module Async
163
151
  # If `graceful` is false, skip the SIGINT phase and go directly to SIGKILL.
164
152
  #
165
153
  # @parameter graceful [Boolean | Numeric] Whether to send SIGINT first or skip directly to SIGKILL.
166
- def stop(graceful = GRACEFUL_TIMEOUT)
154
+ def stop(graceful = true)
167
155
  Console.debug(self, "Stopping all processes...", graceful: graceful)
168
156
 
169
157
  # If a timeout is specified, interrupt the children first:
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Container
8
- VERSION = "0.35.1"
8
+ VERSION = "0.37.0"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -28,6 +28,14 @@ Please see the [project documentation](https://socketry.github.io/async-containe
28
28
 
29
29
  Please see the [project releases](https://socketry.github.io/async-container/releases/index) for all releases.
30
30
 
31
+ ### v0.37.0
32
+
33
+ - Rename `ASYNC_CONTAINER_GRACEFUL_TIMEOUT` to `ASYNC_CONTAINER_GRACEFUL_STOP` and apply it at the controller level as `GRACEFUL_STOP`. `Group#stop` now only applies the shutdown policy it is given.
34
+
35
+ ### v0.36.0
36
+
37
+ - Forked containers now fork child processes from a short-lived thread, reducing inherited scheduler and parent stack state in children.
38
+
31
39
  ### v0.35.1
32
40
 
33
41
  - **Fixed**: `Hybrid` container now stops on interrupt instead of restarting indefinitely.
@@ -60,15 +68,6 @@ Please see the [project releases](https://socketry.github.io/async-container/rel
60
68
 
61
69
  - Add `Policy#make_statistics` to allow policies to customize statistics initialization.
62
70
 
63
- ### v0.32.1
64
-
65
- - Expose `Async::Container::Controller` `#notify`, `#container_class`, and `#graceful_stop` for testing.
66
-
67
- ### v0.32.0
68
-
69
- - Minor **breaking** changes to `Async::Container::Policy` interface.
70
- - Expose `Async::Container::Statistics::Rate#window`.
71
-
72
71
  ## Contributing
73
72
 
74
73
  We welcome contributions to this project.
data/releases.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Releases
2
2
 
3
+ ## v0.37.0
4
+
5
+ - Rename `ASYNC_CONTAINER_GRACEFUL_TIMEOUT` to `ASYNC_CONTAINER_GRACEFUL_STOP` and apply it at the controller level as `GRACEFUL_STOP`. `Group#stop` now only applies the shutdown policy it is given.
6
+
7
+ ## v0.36.0
8
+
9
+ - Forked containers now fork child processes from a short-lived thread, reducing inherited scheduler and parent stack state in children.
10
+
3
11
  ## v0.35.1
4
12
 
5
13
  - **Fixed**: `Hybrid` container now stops on interrupt instead of restarting indefinitely.
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.35.1
4
+ version: 0.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file