process_bot 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/process_bot/process/handlers/sidekiq.rb +105 -28
- data/lib/process_bot/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a955f30c30ca3ec6ae94f3684d492c06b7a0d40042c5de324ced6681720fbb4b
|
|
4
|
+
data.tar.gz: eaae86a1fead6761d82a2f8bd82fa73772351c2e7c307ac3b0e681e435c798bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9ed08da8b21e32e38d93fb65bff64ec3ef90678ae210b17cc11640829e24c29ef132955ca7fe102444f4f470c2468ce03d78a2b68b3b468a066e84f9126a264a
|
|
7
|
+
data.tar.gz: 86ba81368cbddf10daf0b8ec9f189c03214e6ea15fb03be45a1e68aaf774f9043e48c608ce64e7933a3f04fc19a6a013c16f03b93773eb1d5a6e03daad52758b
|
data/Gemfile.lock
CHANGED
|
@@ -25,6 +25,41 @@ class ProcessBot::Process::Handlers::Sidekiq
|
|
|
25
25
|
!value || value == "false"
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def process_running?(pid)
|
|
29
|
+
return false unless pid
|
|
30
|
+
|
|
31
|
+
Process.getpgid(pid)
|
|
32
|
+
true
|
|
33
|
+
rescue Errno::ESRCH
|
|
34
|
+
false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def related_sidekiq_pid
|
|
38
|
+
related_sidekiq_processes = process.runner.related_sidekiq_processes
|
|
39
|
+
if related_sidekiq_processes.empty?
|
|
40
|
+
logger.logs "No related Sidekiq processes found while refreshing PID"
|
|
41
|
+
return nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
related_sidekiq_processes.first.pid
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def update_current_pid(new_pid)
|
|
48
|
+
logger.logs "Refreshing Sidekiq PID from #{current_pid || 'nil'} to #{new_pid}"
|
|
49
|
+
options.events.call(:on_process_started, pid: new_pid)
|
|
50
|
+
new_pid
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def refresh_current_pid(only_if_present: false)
|
|
54
|
+
return nil if only_if_present && !current_pid
|
|
55
|
+
return current_pid if process_running?(current_pid)
|
|
56
|
+
|
|
57
|
+
new_pid = related_sidekiq_pid
|
|
58
|
+
return nil unless new_pid
|
|
59
|
+
|
|
60
|
+
update_current_pid(new_pid)
|
|
61
|
+
end
|
|
62
|
+
|
|
28
63
|
def fetch(*args, **opts)
|
|
29
64
|
options.fetch(*args, **opts)
|
|
30
65
|
end
|
|
@@ -43,6 +78,61 @@ class ProcessBot::Process::Handlers::Sidekiq
|
|
|
43
78
|
options.set(*args, **opts)
|
|
44
79
|
end
|
|
45
80
|
|
|
81
|
+
def send_tstp_or_return
|
|
82
|
+
Process.kill("TSTP", current_pid)
|
|
83
|
+
true
|
|
84
|
+
rescue Errno::ESRCH
|
|
85
|
+
logger.logs "Sidekiq PID #{current_pid} disappeared before TSTP"
|
|
86
|
+
false
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def ensure_current_pid?
|
|
90
|
+
unless current_pid
|
|
91
|
+
warn "Sidekiq not running with a PID"
|
|
92
|
+
return false
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
unless refresh_current_pid
|
|
96
|
+
logger.logs "Sidekiq PID not running and no replacement found - nothing to stop"
|
|
97
|
+
return false
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
true
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def terminate_pid(pid)
|
|
104
|
+
Process.kill("TERM", pid)
|
|
105
|
+
rescue Errno::ESRCH
|
|
106
|
+
logger.logs "Sidekiq PID #{pid} is not running - nothing to stop"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def terminate_related_sidekiq_processes
|
|
110
|
+
related_sidekiq_processes = process.runner.related_sidekiq_processes
|
|
111
|
+
|
|
112
|
+
if related_sidekiq_processes.empty?
|
|
113
|
+
logger.error "#{handler_name} didn't have any processes running"
|
|
114
|
+
return
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
related_sidekiq_processes.each do |related_sidekiq_process|
|
|
118
|
+
terminate_pid(related_sidekiq_process.pid)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def handle_graceful_wait(wait_for_gracefully_stopped)
|
|
123
|
+
if false_value?(wait_for_gracefully_stopped)
|
|
124
|
+
logger.logs "Dont wait for gracefully stopped - doing that in fork..."
|
|
125
|
+
|
|
126
|
+
daemonize do
|
|
127
|
+
wait_for_no_jobs_and_stop_sidekiq
|
|
128
|
+
exit
|
|
129
|
+
end
|
|
130
|
+
else
|
|
131
|
+
logger.logs "Wait for gracefully stopped..."
|
|
132
|
+
wait_for_no_jobs_and_stop_sidekiq
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
46
136
|
def start_command # rubocop:disable Metrics/AbcSize
|
|
47
137
|
args = []
|
|
48
138
|
|
|
@@ -71,39 +161,20 @@ class ProcessBot::Process::Handlers::Sidekiq
|
|
|
71
161
|
wait_for_gracefully_stopped = args.fetch(:wait_for_gracefully_stopped, true)
|
|
72
162
|
process.set_stopped
|
|
73
163
|
|
|
74
|
-
unless
|
|
75
|
-
warn "Sidekiq not running with a PID"
|
|
76
|
-
return
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
Process.kill("TSTP", current_pid)
|
|
164
|
+
return unless ensure_current_pid?
|
|
80
165
|
|
|
81
|
-
|
|
82
|
-
logger.logs "Dont wait for gracefully stopped - doing that in fork..."
|
|
166
|
+
return unless send_tstp_or_return
|
|
83
167
|
|
|
84
|
-
|
|
85
|
-
wait_for_no_jobs_and_stop_sidekiq
|
|
86
|
-
exit
|
|
87
|
-
end
|
|
88
|
-
else
|
|
89
|
-
logger.logs "Wait for gracefully stopped..."
|
|
90
|
-
wait_for_no_jobs_and_stop_sidekiq
|
|
91
|
-
end
|
|
168
|
+
handle_graceful_wait(wait_for_gracefully_stopped)
|
|
92
169
|
end
|
|
93
170
|
|
|
94
171
|
def stop(**_args)
|
|
172
|
+
refresh_current_pid(only_if_present: true)
|
|
173
|
+
|
|
95
174
|
if current_pid
|
|
96
|
-
|
|
175
|
+
terminate_pid(current_pid)
|
|
97
176
|
else
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if related_sidekiq_processes.empty?
|
|
101
|
-
logger.error "#{handler_name} didn't have any processes running"
|
|
102
|
-
else
|
|
103
|
-
related_sidekiq_processes.each do |related_sidekiq_process|
|
|
104
|
-
Process.kill("TERM", related_sidekiq_process.pid)
|
|
105
|
-
end
|
|
106
|
-
end
|
|
177
|
+
terminate_related_sidekiq_processes
|
|
107
178
|
end
|
|
108
179
|
end
|
|
109
180
|
|
|
@@ -111,7 +182,10 @@ class ProcessBot::Process::Handlers::Sidekiq
|
|
|
111
182
|
loop do
|
|
112
183
|
found_process = false
|
|
113
184
|
|
|
114
|
-
|
|
185
|
+
unless refresh_current_pid
|
|
186
|
+
logger.logs "Sidekiq PID not running while waiting for jobs"
|
|
187
|
+
return
|
|
188
|
+
end
|
|
115
189
|
|
|
116
190
|
Knj::Unix_proc.list("grep" => current_pid) do |process|
|
|
117
191
|
process_command = process.data.fetch("cmd")
|
|
@@ -130,7 +204,10 @@ class ProcessBot::Process::Handlers::Sidekiq
|
|
|
130
204
|
return if running_jobs.zero? # rubocop:disable Lint/NonLocalExitFromIterator
|
|
131
205
|
end
|
|
132
206
|
|
|
133
|
-
|
|
207
|
+
unless found_process
|
|
208
|
+
logger.logs "Couldn't find running process with PID #{current_pid}"
|
|
209
|
+
return
|
|
210
|
+
end
|
|
134
211
|
|
|
135
212
|
sleep 1
|
|
136
213
|
end
|
data/lib/process_bot/version.rb
CHANGED