@@ -22,6 +22,9 @@ class Worker
22
22
23
23
attr_accessor :term_timeout
24
24
25
+ # decide whether to use new_kill_child logic
26
+ attr_accessor :term_child
27
+
25
28
attr_writer :to_s
26
29
27
30
# Returns an array of all worker objects.
@@ -278,7 +281,11 @@ def register_signal_handlers
278
281
279
282
begin
280
283
trap ( 'QUIT' ) { shutdown }
281
- trap ( 'USR1' ) { kill_child }
284
+ if term_child
285
+ trap ( 'USR1' ) { new_kill_child }
286
+ else
287
+ trap ( 'USR1' ) { kill_child }
288
+ end
282
289
trap ( 'USR2' ) { pause_processing }
283
290
trap ( 'CONT' ) { unpause_processing }
284
291
rescue ArgumentError
@@ -310,18 +317,36 @@ def shutdown
310
317
# Kill the child and shutdown immediately.
311
318
def shutdown!
312
319
shutdown
313
- kill_child
320
+ if term_child
321
+ new_kill_child
322
+ else
323
+ kill_child
324
+ end
314
325
end
315
326
316
327
# Should this worker shutdown as soon as current job is finished?
317
328
def shutdown?
318
329
@shutdown
319
330
end
320
331
332
+ # Kills the forked child immediately, without remorse. The job it
333
+ # is processing will not be completed.
334
+ def kill_child
335
+ if @child
336
+ log! "Killing child at #{ @child } "
337
+ if system ( "ps -o pid,state -p #{ @child } " )
338
+ Process . kill ( "KILL" , @child ) rescue nil
339
+ else
340
+ log! "Child #{ @child } not found, restarting."
341
+ shutdown
342
+ end
343
+ end
344
+ end
345
+
321
346
# Kills the forked child immediately with minimal remorse. The job it
322
347
# is processing will not be completed. Send the child a TERM signal,
323
348
# wait 5 seconds, and then a KILL signal if it has not quit
324
- def kill_child
349
+ def new_kill_child
325
350
if @child
326
351
unless Process . waitpid ( @child , Process ::WNOHANG )
327
352
log! "Sending TERM signal to child #{ @child } "
0 commit comments