async-container 0.16.4 → 0.16.5
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 +4 -4
- data/.github/workflows/development.yml +2 -2
- data/async-container.gemspec +1 -1
- data/lib/async/container/controller.rb +4 -1
- data/lib/async/container/group.rb +2 -0
- data/lib/async/container/hybrid.rb +11 -2
- data/lib/async/container/thread.rb +1 -0
- data/lib/async/container/version.rb +1 -1
- data/spec/async/container/controller_spec.rb +43 -0
- data/spec/async/container/dots.rb +2 -7
- metadata +3 -7
- data/.travis.yml +0 -21
- data/Rakefile +0 -8
- data/spec/async/container/signal_spec.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 366f5bcb56207cad5c7989c0384d2017d86603a19336fca1228ca7d0dc4684cc
|
4
|
+
data.tar.gz: 6f8e3410a31b4ffeb091256e49a0c553714ce974a401efa0e03dc8832da751a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cadf260da393227a17a340e16a12f81b9baa96f144be7d106397521d5259bf9963ed135fbabbc270d7df54501b72b99e47959cc3462ee870e0cbb2bcf9886509
|
7
|
+
data.tar.gz: 1a488679a02e575fcbb8c1a6e6ffa220b1b83cb0a84025c431ba461a4c70f840d26b3e65b9f95df634bd925b79557cb11b76c7c2582eeaca4bc996bf6a04f9c1
|
@@ -11,10 +11,10 @@ jobs:
|
|
11
11
|
- macos
|
12
12
|
|
13
13
|
ruby:
|
14
|
-
- 2.4
|
15
14
|
- 2.5
|
16
15
|
- 2.6
|
17
16
|
- 2.7
|
17
|
+
- jruby
|
18
18
|
|
19
19
|
include:
|
20
20
|
- os: 'ubuntu'
|
@@ -25,7 +25,7 @@ jobs:
|
|
25
25
|
|
26
26
|
steps:
|
27
27
|
- uses: actions/checkout@v1
|
28
|
-
- uses:
|
28
|
+
- uses: ruby/setup-ruby@v1
|
29
29
|
with:
|
30
30
|
ruby-version: ${{matrix.ruby}}
|
31
31
|
- name: Install dependencies
|
data/async-container.gemspec
CHANGED
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "covered"
|
31
31
|
spec.add_development_dependency "bundler"
|
32
32
|
spec.add_development_dependency "rspec", "~> 3.6"
|
33
|
-
spec.add_development_dependency "
|
33
|
+
spec.add_development_dependency "bake-bundler"
|
34
34
|
end
|
@@ -55,7 +55,9 @@ module Async
|
|
55
55
|
|
56
56
|
@signals = {}
|
57
57
|
|
58
|
-
trap(SIGHUP
|
58
|
+
trap(SIGHUP) do
|
59
|
+
self.restart
|
60
|
+
end
|
59
61
|
end
|
60
62
|
|
61
63
|
def state_string
|
@@ -138,6 +140,7 @@ module Async
|
|
138
140
|
old_container = @container
|
139
141
|
@container = container
|
140
142
|
|
143
|
+
Async.logger.debug(self, "Stopping old container...")
|
141
144
|
old_container&.stop
|
142
145
|
@notify&.ready!
|
143
146
|
rescue
|
@@ -69,12 +69,14 @@ module Async
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def interrupt
|
72
|
+
Async.logger.debug(self, "Sending interrupt to #{@running.size} running processes...")
|
72
73
|
@running.each_value do |fiber|
|
73
74
|
fiber.resume(Interrupt)
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
77
78
|
def terminate
|
79
|
+
Async.logger.debug(self, "Sending terminate to #{@running.size} running processes...")
|
78
80
|
@running.each_value do |fiber|
|
79
81
|
fiber.resume(Terminate)
|
80
82
|
end
|
@@ -33,12 +33,21 @@ module Async
|
|
33
33
|
threads = (count / forks).ceil
|
34
34
|
|
35
35
|
forks.times do
|
36
|
-
self.spawn(**options) do
|
37
|
-
container = Threaded
|
36
|
+
self.spawn(**options) do |instance|
|
37
|
+
container = Threaded.new
|
38
38
|
|
39
39
|
container.run(count: threads, **options, &block)
|
40
40
|
|
41
|
+
container.wait_until_ready
|
42
|
+
instance.ready!
|
43
|
+
|
41
44
|
container.wait
|
45
|
+
rescue Async::Container::Terminate
|
46
|
+
# Stop it immediately:
|
47
|
+
container.stop(false)
|
48
|
+
ensure
|
49
|
+
# Stop it gracefully (also code path for Interrupt):
|
50
|
+
container.stop
|
42
51
|
end
|
43
52
|
end
|
44
53
|
|
@@ -102,4 +102,47 @@ RSpec.describe Async::Container::Controller do
|
|
102
102
|
end.to raise_exception(Async::Container::InitializationError)
|
103
103
|
end
|
104
104
|
end
|
105
|
+
|
106
|
+
context 'with signals' do
|
107
|
+
let(:controller_path) {File.expand_path("dots.rb", __dir__)}
|
108
|
+
|
109
|
+
let(:pipe) {IO.pipe}
|
110
|
+
let(:input) {pipe.first}
|
111
|
+
let(:output) {pipe.last}
|
112
|
+
|
113
|
+
let(:pid) {Process.spawn("bundle", "exec", controller_path, out: output)}
|
114
|
+
|
115
|
+
before do
|
116
|
+
pid
|
117
|
+
output.close
|
118
|
+
end
|
119
|
+
|
120
|
+
after do
|
121
|
+
Process.kill(:KILL, pid)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "restarts children when receiving SIGHUP" do
|
125
|
+
expect(input.read(1)).to be == '.'
|
126
|
+
|
127
|
+
Process.kill(:HUP, pid)
|
128
|
+
|
129
|
+
expect(input.read(2)).to be == 'I.'
|
130
|
+
end
|
131
|
+
|
132
|
+
it "exits gracefully when receiving SIGINT" do
|
133
|
+
expect(input.read(1)).to be == '.'
|
134
|
+
|
135
|
+
Process.kill(:INT, pid)
|
136
|
+
|
137
|
+
expect(input.read).to be == 'I'
|
138
|
+
end
|
139
|
+
|
140
|
+
it "exits gracefully when receiving SIGTERM" do
|
141
|
+
expect(input.read(1)).to be == '.'
|
142
|
+
|
143
|
+
Process.kill(:TERM, pid)
|
144
|
+
|
145
|
+
expect(input.read).to be == 'T'
|
146
|
+
end
|
147
|
+
end
|
105
148
|
end
|
@@ -2,9 +2,8 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require_relative '../../../lib/async/container/controller'
|
5
|
-
require_relative '../../../lib/async/container/forked'
|
6
5
|
|
7
|
-
Console.logger.debug!
|
6
|
+
# Console.logger.debug!
|
8
7
|
|
9
8
|
class Dots < Async::Container::Controller
|
10
9
|
def setup(container)
|
@@ -27,8 +26,4 @@ end
|
|
27
26
|
|
28
27
|
controller = Dots.new
|
29
28
|
|
30
|
-
|
31
|
-
controller.run
|
32
|
-
ensure
|
33
|
-
$stderr.puts $!
|
34
|
-
end
|
29
|
+
controller.run
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: process-group
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.6'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: bake-bundler
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -134,12 +134,10 @@ files:
|
|
134
134
|
- ".github/workflows/development.yml"
|
135
135
|
- ".gitignore"
|
136
136
|
- ".rspec"
|
137
|
-
- ".travis.yml"
|
138
137
|
- ".yardopts"
|
139
138
|
- Gemfile
|
140
139
|
- Guardfile
|
141
140
|
- README.md
|
142
|
-
- Rakefile
|
143
141
|
- async-container.gemspec
|
144
142
|
- examples/async.rb
|
145
143
|
- examples/channel.rb
|
@@ -180,7 +178,6 @@ files:
|
|
180
178
|
- spec/async/container/notify/pipe_spec.rb
|
181
179
|
- spec/async/container/notify_spec.rb
|
182
180
|
- spec/async/container/shared_examples.rb
|
183
|
-
- spec/async/container/signal_spec.rb
|
184
181
|
- spec/async/container/threaded_spec.rb
|
185
182
|
- spec/async/container_spec.rb
|
186
183
|
- spec/spec_helper.rb
|
@@ -216,7 +213,6 @@ test_files:
|
|
216
213
|
- spec/async/container/notify/pipe_spec.rb
|
217
214
|
- spec/async/container/notify_spec.rb
|
218
215
|
- spec/async/container/shared_examples.rb
|
219
|
-
- spec/async/container/signal_spec.rb
|
220
216
|
- spec/async/container/threaded_spec.rb
|
221
217
|
- spec/async/container_spec.rb
|
222
218
|
- spec/spec_helper.rb
|
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: xenial
|
3
|
-
cache: bundler
|
4
|
-
|
5
|
-
matrix:
|
6
|
-
include:
|
7
|
-
- rvm: 2.4
|
8
|
-
- rvm: 2.5
|
9
|
-
- rvm: 2.6
|
10
|
-
# - rvm: 2.6
|
11
|
-
# os: osx
|
12
|
-
- rvm: 2.6
|
13
|
-
env: COVERAGE=BriefSummary,Coveralls
|
14
|
-
- rvm: 2.7
|
15
|
-
- rvm: truffleruby
|
16
|
-
- rvm: jruby-head
|
17
|
-
env: JRUBY_OPTS="--debug -X+O"
|
18
|
-
- rvm: ruby-head
|
19
|
-
allow_failures:
|
20
|
-
- rvm: ruby-head
|
21
|
-
- rvm: jruby-head
|
data/Rakefile
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require "async/container/controller"
|
24
|
-
|
25
|
-
RSpec.describe Async::Container::Controller do
|
26
|
-
let(:controller_path) {File.expand_path("dots.rb", __dir__)}
|
27
|
-
|
28
|
-
let(:pipe) {IO.pipe}
|
29
|
-
let(:input) {pipe.first}
|
30
|
-
let(:output) {pipe.last}
|
31
|
-
|
32
|
-
let(:pid) {Process.spawn(controller_path, out: output)}
|
33
|
-
|
34
|
-
before do
|
35
|
-
pid
|
36
|
-
output.close
|
37
|
-
end
|
38
|
-
|
39
|
-
after do
|
40
|
-
Process.kill(:KILL, pid)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "restarts children when receiving SIGHUP" do
|
44
|
-
expect(input.read(1)).to be == '.'
|
45
|
-
|
46
|
-
Process.kill(:HUP, pid)
|
47
|
-
|
48
|
-
expect(input.read(2)).to be == 'I.'
|
49
|
-
end
|
50
|
-
|
51
|
-
it "exits gracefully when receiving SIGINT" do
|
52
|
-
expect(input.read(1)).to be == '.'
|
53
|
-
|
54
|
-
Process.kill(:INT, pid)
|
55
|
-
|
56
|
-
expect(input.read).to be == 'I'
|
57
|
-
end
|
58
|
-
|
59
|
-
it "exits gracefully when receiving SIGTERM" do
|
60
|
-
expect(input.read(1)).to be == '.'
|
61
|
-
|
62
|
-
Process.kill(:TERM, pid)
|
63
|
-
|
64
|
-
expect(input.read).to be == 'T'
|
65
|
-
end
|
66
|
-
end
|