async-container 0.16.1 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/container/controller.rb +12 -9
- data/lib/async/container/generic.rb +1 -1
- data/lib/async/container/notify.rb +3 -1
- data/lib/async/container/notify/console.rb +70 -0
- data/lib/async/container/process.rb +1 -7
- data/lib/async/container/thread.rb +1 -5
- data/lib/async/container/version.rb +1 -1
- data/spec/async/container/controller_spec.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2793bfea616c3829e4e892c854772aba2ace1b28bc425fa792c190882e6290f
|
4
|
+
data.tar.gz: cd78711d9c21080560d2ed175c240a5cd5640b185f73a8aff93f431f46acb89a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7806e094721c20aa4f160b3505dfe6f21792d96f4e6d697c6f4670990a11ce7a6c03eeed22ef381f229d2014478b935bcf5e4af036a650fa1849f8fa6d6cb560
|
7
|
+
data.tar.gz: 744567b07a9aedfc02ad12e06f4620013e8345a260970e78c88fd39a4e4a90c7d4fcc691724c94009f3b9eb2ead81948139223d8a28b3c9f4b4ca3afdcbd69bd
|
@@ -28,9 +28,10 @@ require_relative 'notify'
|
|
28
28
|
|
29
29
|
module Async
|
30
30
|
module Container
|
31
|
-
class
|
31
|
+
class InitializationError < Error
|
32
32
|
def initialize(container)
|
33
33
|
super("Could not create container!")
|
34
|
+
|
34
35
|
@container = container
|
35
36
|
end
|
36
37
|
|
@@ -117,7 +118,7 @@ module Async
|
|
117
118
|
rescue
|
118
119
|
@notify&.error!($!.to_s)
|
119
120
|
|
120
|
-
raise
|
121
|
+
raise InitializationError, container
|
121
122
|
end
|
122
123
|
|
123
124
|
# Wait for all child processes to enter the ready state.
|
@@ -130,7 +131,7 @@ module Async
|
|
130
131
|
|
131
132
|
container.stop
|
132
133
|
|
133
|
-
raise
|
134
|
+
raise InitializationError, container
|
134
135
|
end
|
135
136
|
|
136
137
|
# Make this swap as atomic as possible:
|
@@ -142,6 +143,8 @@ module Async
|
|
142
143
|
rescue
|
143
144
|
# If we are leaving this function with an exception, try to kill the container:
|
144
145
|
container&.stop(false)
|
146
|
+
|
147
|
+
raise
|
145
148
|
end
|
146
149
|
|
147
150
|
def reload
|
@@ -152,7 +155,7 @@ module Async
|
|
152
155
|
begin
|
153
156
|
self.setup(@container)
|
154
157
|
rescue
|
155
|
-
raise
|
158
|
+
raise InitializationError, container
|
156
159
|
end
|
157
160
|
|
158
161
|
# Wait for all child processes to enter the ready state.
|
@@ -163,7 +166,7 @@ module Async
|
|
163
166
|
if @container.failed?
|
164
167
|
@notify.error!("Container failed!")
|
165
168
|
|
166
|
-
raise
|
169
|
+
raise InitializationError, @container
|
167
170
|
else
|
168
171
|
@notify&.ready!
|
169
172
|
end
|
@@ -188,8 +191,8 @@ module Async
|
|
188
191
|
if handler = @signals[exception.signo]
|
189
192
|
begin
|
190
193
|
handler.call
|
191
|
-
rescue
|
192
|
-
Async.logger.error(self) {
|
194
|
+
rescue InitializationError => error
|
195
|
+
Async.logger.error(self) {error}
|
193
196
|
end
|
194
197
|
else
|
195
198
|
raise
|
@@ -200,9 +203,9 @@ module Async
|
|
200
203
|
self.stop(true)
|
201
204
|
rescue Terminate
|
202
205
|
self.stop(false)
|
203
|
-
else
|
204
|
-
self.stop(true)
|
205
206
|
ensure
|
207
|
+
self.stop(true)
|
208
|
+
|
206
209
|
# Restore the interrupt handler:
|
207
210
|
Signal.trap(:INT, interrupt_action)
|
208
211
|
Signal.trap(:TERM, terminate_action)
|
@@ -23,6 +23,7 @@
|
|
23
23
|
|
24
24
|
require_relative 'notify/pipe'
|
25
25
|
require_relative 'notify/socket'
|
26
|
+
require_relative 'notify/console'
|
26
27
|
|
27
28
|
module Async
|
28
29
|
module Container
|
@@ -34,7 +35,8 @@ module Async
|
|
34
35
|
# Select the best available client:
|
35
36
|
@@client ||= (
|
36
37
|
Pipe.open! ||
|
37
|
-
Socket.open!
|
38
|
+
Socket.open! ||
|
39
|
+
Console.open!
|
38
40
|
)
|
39
41
|
end
|
40
42
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
# THE SOFTWARE.
|
23
|
+
|
24
|
+
require_relative 'client'
|
25
|
+
|
26
|
+
require 'console/logger'
|
27
|
+
|
28
|
+
module Async
|
29
|
+
module Container
|
30
|
+
module Notify
|
31
|
+
class Console < Client
|
32
|
+
def self.open!(logger = ::Console.logger)
|
33
|
+
self.new(logger)
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(logger)
|
37
|
+
@logger = logger
|
38
|
+
end
|
39
|
+
|
40
|
+
def send(level: :debug, **message)
|
41
|
+
@logger.send(level, self) {message[:status]}
|
42
|
+
end
|
43
|
+
|
44
|
+
def ready!(**message)
|
45
|
+
send(ready: true, **message)
|
46
|
+
end
|
47
|
+
|
48
|
+
def restarting!(**message)
|
49
|
+
message[:ready] = false
|
50
|
+
message[:reloading] = true
|
51
|
+
message[:status] ||= "Restarting..."
|
52
|
+
|
53
|
+
send(**message)
|
54
|
+
end
|
55
|
+
|
56
|
+
def reloading!(**message)
|
57
|
+
message[:ready] = false
|
58
|
+
message[:reloading] = true
|
59
|
+
message[:status] ||= "Reloading..."
|
60
|
+
|
61
|
+
send(**message)
|
62
|
+
end
|
63
|
+
|
64
|
+
def error!(text, **message)
|
65
|
+
send(status: text, level: :error, **message)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -119,13 +119,7 @@ module Async
|
|
119
119
|
attr :name
|
120
120
|
|
121
121
|
def to_s
|
122
|
-
|
123
|
-
"\#<#{self.class} #{@name} -> #{@status}>"
|
124
|
-
elsif @pid
|
125
|
-
"\#<#{self.class} #{@name} -> #{@pid}>"
|
126
|
-
else
|
127
|
-
"\#<#{self.class} #{@name}>"
|
128
|
-
end
|
122
|
+
"\#<#{self.class} #{@name}>"
|
129
123
|
end
|
130
124
|
|
131
125
|
def close
|
@@ -91,5 +91,16 @@ RSpec.describe Async::Container::Controller do
|
|
91
91
|
|
92
92
|
subject.stop
|
93
93
|
end
|
94
|
+
|
95
|
+
it "propagates exceptions" do
|
96
|
+
def subject.setup(container)
|
97
|
+
raise "Boom!"
|
98
|
+
end
|
99
|
+
|
100
|
+
expect do
|
101
|
+
subject.run
|
102
|
+
end.to raise_exception(Async::Container::InitializationError)
|
103
|
+
end
|
104
|
+
|
94
105
|
end
|
95
106
|
end
|
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.2
|
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-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: process-group
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/async/container/keyed.rb
|
164
164
|
- lib/async/container/notify.rb
|
165
165
|
- lib/async/container/notify/client.rb
|
166
|
+
- lib/async/container/notify/console.rb
|
166
167
|
- lib/async/container/notify/pipe.rb
|
167
168
|
- lib/async/container/notify/server.rb
|
168
169
|
- lib/async/container/notify/socket.rb
|