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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efe790ddbf87b5df04f8b9e441b27fda5fb1cb69cc6fa2b800a64d3f6af46f24
4
- data.tar.gz: 6500f4e2b6d21d8f78a6f99065c0af795694f003c15f1f265634be36a4c8f229
3
+ metadata.gz: e2793bfea616c3829e4e892c854772aba2ace1b28bc425fa792c190882e6290f
4
+ data.tar.gz: cd78711d9c21080560d2ed175c240a5cd5640b185f73a8aff93f431f46acb89a
5
5
  SHA512:
6
- metadata.gz: d27b92c0e9333dd121f5f5d65be1249073d1e06e55d018f3d91c0670feb14b8463629783c0fe74c416e8f6df1d08f1c84270a5bc19ec040c68c6778da8bdf02d
7
- data.tar.gz: ddb9d010c191f469347a759ff2c90fd8d1cab8fddcb0ab6245357098bb1d576843fd351c767ea1dd9d8302dabe549fef04444e090960e0c9ee3d173ff5cbeed4
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 ContainerError < Error
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 ContainerError, container
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 ContainerError, container
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 ContainerError, container
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 ContainerError, @container
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 ContainerError => failure
192
- Async.logger.error(self) {failure}
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)
@@ -144,7 +144,7 @@ module Async
144
144
  end
145
145
 
146
146
  if status.success?
147
- Async.logger.info(self) {"#{child} #{status}"}
147
+ Async.logger.info(self) {"#{child} exited with #{status}"}
148
148
  else
149
149
  @statistics.failure!
150
150
  Async.logger.error(self) {status}
@@ -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
- if @status
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
@@ -124,11 +124,7 @@ module Async
124
124
  end
125
125
 
126
126
  def to_s
127
- if @status
128
- "\#<#{self.class} #{@thread.name} -> #{@status}>"
129
- else
130
- "\#<#{self.class} #{@thread.name}>"
131
- end
127
+ "\#<#{self.class} #{@thread.name}>"
132
128
  end
133
129
 
134
130
  def close
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module Container
25
- VERSION = "0.16.1"
25
+ VERSION = "0.16.2"
26
26
  end
27
27
  end
@@ -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.1
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-02-01 00:00:00.000000000 Z
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