pastry 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pastry.rb +17 -5
- metadata +2 -2
data/lib/pastry.rb
CHANGED
@@ -65,6 +65,8 @@ class Pastry
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
+
GRACE = 60
|
69
|
+
|
68
70
|
attr_accessor :pids
|
69
71
|
|
70
72
|
def do_sanity_checks
|
@@ -200,10 +202,10 @@ class Pastry
|
|
200
202
|
Process.detach(pid)
|
201
203
|
|
202
204
|
begin
|
203
|
-
Timeout.timeout(
|
205
|
+
Timeout.timeout(GRACE) { sleep 0.5 until File.exists?(pidfile) }
|
204
206
|
rescue Timeout::Error => e
|
205
207
|
Process.kill('TERM', pid) rescue nil
|
206
|
-
logger.error "new master failed to spawn within #{
|
208
|
+
logger.error "new master failed to spawn within #{GRACE} secs, check logs"
|
207
209
|
@running = true
|
208
210
|
FileUtils.mv "#{pidfile}.old", pidfile
|
209
211
|
else
|
@@ -220,9 +222,9 @@ class Pastry
|
|
220
222
|
pids.each {|pid| Process.kill(signal, pid) rescue nil}
|
221
223
|
return if signal == 'KILL'
|
222
224
|
|
223
|
-
logger.info "waiting up to #{
|
225
|
+
logger.info "waiting up to #{GRACE} seconds"
|
224
226
|
begin
|
225
|
-
Timeout.timeout(
|
227
|
+
Timeout.timeout(GRACE) do
|
226
228
|
alive = pids
|
227
229
|
until alive.empty?
|
228
230
|
sleep 0.1
|
@@ -243,7 +245,7 @@ class Pastry
|
|
243
245
|
$0 = "#{name ? "%s worker" % name : "pastry chef"} #{worker} (started: #{Time.now})"
|
244
246
|
EM.epoll
|
245
247
|
EM.set_descriptor_table_size(max_connections)
|
246
|
-
EM.run { Backend.new.start(server) }
|
248
|
+
EM.run { Backend.new(timeout: timeout).start(server) }
|
247
249
|
end
|
248
250
|
end
|
249
251
|
|
@@ -252,6 +254,11 @@ class Pastry
|
|
252
254
|
end
|
253
255
|
|
254
256
|
class Backend < Thin::Backends::Base
|
257
|
+
def initialize options = {}
|
258
|
+
super()
|
259
|
+
@timeout = options.fetch(:timeout, 30)
|
260
|
+
end
|
261
|
+
|
255
262
|
def start server
|
256
263
|
@stopping = false
|
257
264
|
@running = true
|
@@ -261,6 +268,11 @@ class Pastry
|
|
261
268
|
@signature = EM.attach_server_socket(server, Thin::Connection, &method(:initialize_connection))
|
262
269
|
end
|
263
270
|
|
271
|
+
def initialize_connection connection
|
272
|
+
super
|
273
|
+
connection.comm_inactivity_timeout = @timeout
|
274
|
+
end
|
275
|
+
|
264
276
|
def trap_signals!
|
265
277
|
# ignore SIGCHLD, can be overriden by app.
|
266
278
|
Signal.trap('CHLD', 'IGNORE')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pastry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -48,7 +48,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
48
|
requirements:
|
49
49
|
- - ! '>='
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
hash:
|
51
|
+
hash: 1587036579679501269
|
52
52
|
version: '0'
|
53
53
|
segments:
|
54
54
|
- 0
|