process_bot 0.1.17 → 0.1.18
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/CHANGELOG.md +1 -0
- data/Gemfile.lock +1 -1
- data/lib/process_bot/control_socket.rb +8 -1
- data/lib/process_bot/process.rb +38 -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: 00371cf3c9ed3fa904d5d3a8655be99178ce77a729ab2aad459572fc63bb4779
|
|
4
|
+
data.tar.gz: db9145067629c7872c810c03e1e97caa6c626837ec26d07fa6ceeebf1a623bdd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 89a0dde6cbadf510efb51b07f690ec90ca03af46ba06c9a1eca1f75a86e718bf23d263207aedd5a2763463e9470d9655d81487d5073f24a077edd1798acb2691
|
|
7
|
+
data.tar.gz: 27a95d5f8911f704c15faf58339c0173ca6cc01a3d7e8caa70743d6f3eadbbb9a44122b2ece7e74feaf4b7b6e7a03b1d7809e22cfa26efb4eb9967972f6846ff
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -79,13 +79,20 @@ class ProcessBot::ControlSocket
|
|
|
79
79
|
|
|
80
80
|
if command_type == "graceful" || command_type == "graceful_no_wait" || command_type == "stop"
|
|
81
81
|
begin
|
|
82
|
+
unless process.accept_control_commands?
|
|
83
|
+
client.puts(JSON.generate(type: "error", message: "ProcessBot is shutting down", backtrace: Thread.current.backtrace))
|
|
84
|
+
break
|
|
85
|
+
end
|
|
86
|
+
|
|
82
87
|
command_options = if command["options"]
|
|
83
88
|
symbolize_keys(command.fetch("options"))
|
|
84
89
|
else
|
|
85
90
|
{}
|
|
86
91
|
end
|
|
87
92
|
|
|
88
|
-
|
|
93
|
+
process.with_control_command do
|
|
94
|
+
run_command(command_type, command_options, client)
|
|
95
|
+
end
|
|
89
96
|
rescue => e # rubocop:disable Style/RescueStandardError
|
|
90
97
|
logger.error e.message
|
|
91
98
|
logger.error e.backtrace
|
data/lib/process_bot/process.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "forwardable"
|
|
2
2
|
require "json"
|
|
3
|
+
require "monitor"
|
|
3
4
|
require "string-cases"
|
|
4
5
|
|
|
5
6
|
class ProcessBot::Process
|
|
@@ -12,11 +13,14 @@ class ProcessBot::Process
|
|
|
12
13
|
autoload :Handlers, "#{__dir__}/process/handlers"
|
|
13
14
|
autoload :Runner, "#{__dir__}/process/runner"
|
|
14
15
|
|
|
15
|
-
attr_reader :current_pid, :current_process_title, :options, :port, :stopped
|
|
16
|
+
attr_reader :control_command_monitor, :current_pid, :current_process_title, :options, :port, :stopped
|
|
16
17
|
|
|
17
18
|
def initialize(options)
|
|
18
19
|
@options = options
|
|
19
20
|
@stopped = false
|
|
21
|
+
@accept_control_commands = true
|
|
22
|
+
@control_command_monitor = Monitor.new
|
|
23
|
+
@control_commands_in_flight = 0
|
|
20
24
|
|
|
21
25
|
options.events.connect(:on_process_started, &method(:on_process_started)) # rubocop:disable Performance/MethodObjectAsBlock
|
|
22
26
|
options.events.connect(:on_socket_opened, &method(:on_socket_opened)) # rubocop:disable Performance/MethodObjectAsBlock
|
|
@@ -86,6 +90,8 @@ class ProcessBot::Process
|
|
|
86
90
|
run
|
|
87
91
|
|
|
88
92
|
if stopped
|
|
93
|
+
stop_accepting_control_commands
|
|
94
|
+
wait_for_control_commands
|
|
89
95
|
break
|
|
90
96
|
else
|
|
91
97
|
logger.logs "Process stopped - starting again after 1 sec"
|
|
@@ -127,4 +133,35 @@ class ProcessBot::Process
|
|
|
127
133
|
@current_process_title = "ProcessBot #{JSON.generate(process_args)}"
|
|
128
134
|
Process.setproctitle(current_process_title)
|
|
129
135
|
end
|
|
136
|
+
|
|
137
|
+
def with_control_command
|
|
138
|
+
control_command_monitor.synchronize do
|
|
139
|
+
@control_commands_in_flight += 1
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
yield
|
|
143
|
+
ensure
|
|
144
|
+
control_command_monitor.synchronize do
|
|
145
|
+
@control_commands_in_flight -= 1
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def accept_control_commands?
|
|
150
|
+
@accept_control_commands
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def stop_accepting_control_commands
|
|
154
|
+
@accept_control_commands = false
|
|
155
|
+
@control_socket&.stop
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def wait_for_control_commands
|
|
159
|
+
sleep 0.1 while control_commands_in_flight.positive?
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def control_commands_in_flight
|
|
163
|
+
control_command_monitor.synchronize do
|
|
164
|
+
@control_commands_in_flight
|
|
165
|
+
end
|
|
166
|
+
end
|
|
130
167
|
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.18
|
|
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-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: knjrbfw
|