solid_queue 0.3.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidQueue::Processes
4
- class GracefulTerminationRequested < Interrupt; end
5
- class ImmediateTerminationRequested < Interrupt; end
6
-
7
- module Signals
8
- extend ActiveSupport::Concern
9
-
10
- private
11
- SIGNALS = %i[ QUIT INT TERM ]
12
-
13
- def register_signal_handlers
14
- SIGNALS.each do |signal|
15
- trap(signal) do
16
- signal_queue << signal
17
- interrupt
18
- end
19
- end
20
- end
21
-
22
- def restore_default_signal_handlers
23
- SIGNALS.each do |signal|
24
- trap(signal, :DEFAULT)
25
- end
26
- end
27
-
28
- def process_signal_queue
29
- while signal = signal_queue.shift
30
- handle_signal(signal)
31
- end
32
- end
33
-
34
- def handle_signal(signal)
35
- case signal
36
- when :TERM, :INT
37
- request_graceful_termination
38
- when :QUIT
39
- request_immediate_termination
40
- else
41
- SolidQueue.instrument :unhandled_signal_error, signal: signal
42
- end
43
- end
44
-
45
- def request_graceful_termination
46
- raise GracefulTerminationRequested
47
- end
48
-
49
- def request_immediate_termination
50
- raise ImmediateTerminationRequested
51
- end
52
-
53
- def signal_processes(pids, signal)
54
- pids.each do |pid|
55
- signal_process pid, signal
56
- end
57
- end
58
-
59
- def signal_process(pid, signal)
60
- ::Process.kill signal, pid
61
- rescue Errno::ESRCH
62
- # Ignore, process died before
63
- end
64
-
65
- def signal_queue
66
- @signal_queue ||= []
67
- end
68
- end
69
- end