process_bot 0.1.15 → 0.1.16
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/README.md +1 -0
- data/lib/process_bot/capistrano/sidekiq.rake +49 -0
- data/lib/process_bot/capistrano/sidekiq_helpers.rb +25 -0
- data/lib/process_bot/process/handlers/sidekiq.rb +10 -0
- data/lib/process_bot/process.rb +2 -1
- data/lib/process_bot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7d79a43f8a6bdf408f637e66fff579115ab45f57f0c8c0314d98c1e84a8f4430
|
|
4
|
+
data.tar.gz: 716c9b8e69f54f1dc60a322d1ddad7f4336b464e338964ffa9f736d7cac11477
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2739cfa0148b5085b45f0ca273d583f609413346e7d7ebed3693fb3715ebeb2ad4c14475b212c82a86e3bc1081585f2edc606c0d2f7ae2159a61722cfc1bc0c1
|
|
7
|
+
data.tar.gz: f59153145d7e36da05d9d9dc98d6e7d2f0a3b8f03fcfb51606b800453685f2fcb45e07eca46395cbdeac095f041749eb2064b9f98bc6dfe1c5e7d3fad5611e35
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -44,6 +44,7 @@ ProcessBot provides these Sidekiq tasks:
|
|
|
44
44
|
- `process_bot:sidekiq:stop`
|
|
45
45
|
- `process_bot:sidekiq:graceful` (stops fetching new jobs and waits for running jobs by default)
|
|
46
46
|
- `process_bot:sidekiq:graceful_no_wait` (stops fetching new jobs and returns immediately)
|
|
47
|
+
- `process_bot:sidekiq:ensure_running` (starts missing processes, ignoring ones in graceful shutdown)
|
|
47
48
|
- `process_bot:sidekiq:restart`
|
|
48
49
|
|
|
49
50
|
You can also skip waiting for graceful completion:
|
|
@@ -70,6 +70,55 @@ namespace :process_bot do
|
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
+
desc "Ensure the configured number of Sidekiq ProcessBots are running (excluding graceful shutdowns)"
|
|
74
|
+
task :ensure_running do
|
|
75
|
+
on roles fetch(:sidekiq_roles) do |role|
|
|
76
|
+
git_plugin.switch_user(role) do
|
|
77
|
+
desired_processes = fetch(:sidekiq_processes).to_i
|
|
78
|
+
running_processes = git_plugin.running_process_bot_processes
|
|
79
|
+
|
|
80
|
+
graceful_processes = running_processes.select do |process_bot_data|
|
|
81
|
+
git_plugin.sidekiq_process_graceful?(process_bot_data)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
active_processes = running_processes - graceful_processes
|
|
85
|
+
|
|
86
|
+
active_indexes = active_processes.filter_map do |process_bot_data|
|
|
87
|
+
git_plugin.process_bot_sidekiq_index(process_bot_data)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
graceful_indexes = graceful_processes.filter_map do |process_bot_data|
|
|
91
|
+
git_plugin.process_bot_sidekiq_index(process_bot_data)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
puts "ProcessBot Sidekiq in graceful shutdown: #{graceful_indexes.join(", ")}" if graceful_indexes.any?
|
|
95
|
+
|
|
96
|
+
desired_indexes = (0...desired_processes).to_a
|
|
97
|
+
missing_indexes = desired_indexes - active_indexes - graceful_indexes
|
|
98
|
+
missing_count = desired_processes - active_indexes.count
|
|
99
|
+
|
|
100
|
+
if missing_count.negative?
|
|
101
|
+
puts "Found #{active_indexes.count} running ProcessBot Sidekiq processes; desired is #{desired_processes}"
|
|
102
|
+
missing_count = 0
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
if missing_indexes.any?
|
|
106
|
+
missing_indexes.each do |idx|
|
|
107
|
+
puts "Starting Sidekiq with ProcessBot #{idx} (missing)"
|
|
108
|
+
git_plugin.start_sidekiq(idx)
|
|
109
|
+
end
|
|
110
|
+
else
|
|
111
|
+
puts "All ProcessBot Sidekiq processes are running (#{active_indexes.count}/#{desired_processes})"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
return unless missing_count > missing_indexes.length
|
|
115
|
+
|
|
116
|
+
puts "Skipped starting #{missing_count - missing_indexes.length} processes because " \
|
|
117
|
+
"they are still in graceful shutdown"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
73
122
|
desc "Restart Sidekiq and ProcessBot"
|
|
74
123
|
task :restart do
|
|
75
124
|
invoke! "process_bot:sidekiq:stop"
|
|
@@ -93,6 +93,31 @@ module ProcessBot::Capistrano::SidekiqHelpers # rubocop:disable Metrics/ModuleLe
|
|
|
93
93
|
processes
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
+
def process_bot_sidekiq_index(process_bot_data)
|
|
97
|
+
process_bot_id = process_bot_data["id"].to_s
|
|
98
|
+
match = process_bot_id.match(/-(\d+)\z/)
|
|
99
|
+
return nil unless match
|
|
100
|
+
|
|
101
|
+
match[1].to_i
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def sidekiq_command_graceful?(command)
|
|
105
|
+
return false unless command
|
|
106
|
+
|
|
107
|
+
normalized_command = command.to_s.downcase
|
|
108
|
+
normalized_command.include?("stopping") || normalized_command.include?("quiet")
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def sidekiq_process_graceful?(process_bot_data)
|
|
112
|
+
sidekiq_pid = process_bot_data["pid"]
|
|
113
|
+
return false unless sidekiq_pid
|
|
114
|
+
|
|
115
|
+
command = backend.capture(:ps, "-o", "command=", "-p", sidekiq_pid.to_s).strip
|
|
116
|
+
sidekiq_command_graceful?(command)
|
|
117
|
+
rescue SSHKit::Command::Failed
|
|
118
|
+
false
|
|
119
|
+
end
|
|
120
|
+
|
|
96
121
|
def sidekiq_user(role = nil)
|
|
97
122
|
if role.nil?
|
|
98
123
|
fetch(:sidekiq_user)
|
|
@@ -215,5 +215,15 @@ class ProcessBot::Process::Handlers::Sidekiq
|
|
|
215
215
|
logger.logs "Wait for no jobs and Stop sidekiq"
|
|
216
216
|
wait_for_no_jobs
|
|
217
217
|
stop
|
|
218
|
+
wait_for_sidekiq_exit
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def wait_for_sidekiq_exit
|
|
222
|
+
return unless current_pid
|
|
223
|
+
|
|
224
|
+
while process_running?(current_pid)
|
|
225
|
+
logger.logs "Waiting for Sidekiq PID #{current_pid} to stop"
|
|
226
|
+
sleep 1
|
|
227
|
+
end
|
|
218
228
|
end
|
|
219
229
|
end
|
data/lib/process_bot/process.rb
CHANGED
|
@@ -106,7 +106,8 @@ class ProcessBot::Process
|
|
|
106
106
|
|
|
107
107
|
def send_control_command(command, **command_options)
|
|
108
108
|
logger.logs "Sending #{command} command"
|
|
109
|
-
client.send_command(command: command, options: options.options.merge(command_options))
|
|
109
|
+
response = client.send_command(command: command, options: options.options.merge(command_options))
|
|
110
|
+
raise "No response from ProcessBot while sending #{command}" if response == :nil
|
|
110
111
|
rescue Errno::ECONNREFUSED => e
|
|
111
112
|
raise e unless options[:ignore_no_process_bot]
|
|
112
113
|
end
|
data/lib/process_bot/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: process_bot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- kaspernj
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
11
|
+
date: 2026-01-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: knjrbfw
|