procon_bypass_man 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +19 -6
- data/.github/workflows/gitleacks.yml +2 -1
- data/.github/workflows/release.yml +1 -0
- data/.github/workflows/ruby.yml +1 -1
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +16 -1
- data/Gemfile +6 -3
- data/Gemfile.lock +3 -3
- data/README.md +17 -8
- data/Steepfile +0 -1
- data/bin/generate_default_app +10 -0
- data/docs/getting_started.md +98 -25
- data/docs/setup_raspi_by_mitamae.md +44 -2
- data/lib/procon_bypass_man/background/job_performer.rb +1 -2
- data/lib/procon_bypass_man/background/job_queue.rb +50 -0
- data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +2 -2
- data/lib/procon_bypass_man/background/jobs/concerns/job_performable.rb +16 -0
- data/lib/procon_bypass_man/background/jobs/post_completed_remote_macro_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_completed_upgrade_pbm_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_error_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_error_reload_config_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_procon_performance_measurements_job.rb +43 -0
- data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_start_reboot_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +1 -1
- data/lib/procon_bypass_man/background.rb +3 -4
- data/lib/procon_bypass_man/bypass/bypass_command.rb +6 -15
- data/lib/procon_bypass_man/bypass/bypass_value.rb +6 -0
- data/lib/procon_bypass_man/bypass/procon_to_switch.rb +107 -0
- data/lib/procon_bypass_man/bypass/switch_to_procon.rb +64 -0
- data/lib/procon_bypass_man/bypass.rb +5 -112
- data/lib/procon_bypass_man/configuration.rb +16 -40
- data/lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb +1 -1
- data/lib/procon_bypass_man/device_connection/procon_setting_overrider.rb +12 -3
- data/lib/procon_bypass_man/procon/macro.rb +1 -1
- data/lib/procon_bypass_man/procon/performance_measurement/last_bypass_at.rb +17 -0
- data/lib/procon_bypass_man/procon/performance_measurement/measurement_collection.rb +9 -0
- data/lib/procon_bypass_man/procon/performance_measurement/measurements_summarizer.rb +84 -0
- data/lib/procon_bypass_man/procon/performance_measurement/procon_performance_span_transfer_job.rb +8 -0
- data/lib/procon_bypass_man/procon/performance_measurement/queue_over_process.rb +38 -0
- data/lib/procon_bypass_man/procon/performance_measurement/span_queue.rb +42 -0
- data/lib/procon_bypass_man/procon/performance_measurement/span_transfer_buffer.rb +39 -0
- data/lib/procon_bypass_man/procon/performance_measurement.rb +103 -0
- data/lib/procon_bypass_man/procon.rb +2 -1
- data/lib/procon_bypass_man/procon_display/bypass_hook.rb +12 -0
- data/lib/procon_bypass_man/procon_display/http_request.rb +31 -0
- data/lib/procon_bypass_man/procon_display/http_response.rb +23 -0
- data/lib/procon_bypass_man/procon_display/server.rb +33 -0
- data/lib/procon_bypass_man/procon_display/server_app.rb +17 -0
- data/lib/procon_bypass_man/procon_display/status.rb +20 -0
- data/lib/procon_bypass_man/procon_display.rb +11 -0
- data/lib/procon_bypass_man/remote_macro/queue_over_process.rb +26 -44
- data/lib/procon_bypass_man/remote_macro/remote_macro_object.rb +22 -24
- data/lib/procon_bypass_man/remote_macro/remote_macro_receiver.rb +1 -1
- data/lib/procon_bypass_man/remote_macro/remote_macro_sender.rb +1 -1
- data/lib/procon_bypass_man/remote_macro/task.rb +1 -5
- data/lib/procon_bypass_man/remote_macro/task_queue.rb +6 -10
- data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb +1 -1
- data/lib/procon_bypass_man/runner.rb +4 -9
- data/lib/procon_bypass_man/scheduler.rb +15 -6
- data/lib/procon_bypass_man/support/callbacks.rb +72 -34
- data/lib/procon_bypass_man/support/can_over_process.rb +60 -0
- data/lib/procon_bypass_man/support/gc.rb +8 -0
- data/lib/procon_bypass_man/support/http_client.rb +9 -6
- data/lib/procon_bypass_man/support/load_agv.rb +20 -0
- data/lib/procon_bypass_man/support/procon_performance_http_client.rb +7 -0
- data/lib/procon_bypass_man/support/retryable.rb +16 -0
- data/lib/procon_bypass_man/support/signal_handler.rb +1 -1
- data/lib/procon_bypass_man/version.rb +1 -1
- data/lib/procon_bypass_man/websocket/client.rb +2 -2
- data/lib/procon_bypass_man/worker.rb +32 -0
- data/lib/procon_bypass_man.rb +41 -10
- data/procon_bypass_man.gemspec +1 -1
- data/project_template/README.md +0 -5
- data/project_template/app.rb +21 -11
- data/project_template/app.rb.erb +62 -0
- data/project_template/lib/app_generator.rb +31 -0
- data/project_template/web.rb +1 -1
- data/sig/main.rbs +10 -52
- data/tmp/.keep +0 -0
- metadata +34 -10
- data/lib/procon_bypass_man/background/job_runner.rb +0 -45
- data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +0 -5
- data/lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb +0 -16
- data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +0 -15
- data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +0 -44
- data/lib/procon_bypass_man/io_monitor.rb +0 -108
- data/lib/procon_bypass_man/support/server_pool.rb +0 -46
@@ -1,30 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
class NonSupportAction < ValidationError; end
|
1
|
+
class ProconBypassMan::RemoteMacro::RemoteMacroObject
|
2
|
+
# valueobjectがvalidatorの責務も持っている. 今度分離する
|
3
|
+
class ValidationError < StandardError; end
|
4
|
+
class MustBeNotNilError < ValidationError; end
|
5
|
+
class NonSupportAction < ValidationError; end
|
7
6
|
|
8
|
-
|
7
|
+
attr_accessor :name, :uuid, :steps
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
# @param [String] name
|
10
|
+
# @param [String] uuid
|
11
|
+
# @param [Array] steps
|
12
|
+
def initialize(name: , uuid:, steps: )
|
13
|
+
@name = name
|
14
|
+
@uuid = uuid
|
15
|
+
@steps = steps
|
16
|
+
freeze
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
19
|
+
# @raise [MustBeNotNilError]
|
20
|
+
# @raise [NonSupportAction]
|
21
|
+
# @return [void]
|
22
|
+
def validate!
|
23
|
+
self.uuid or raise MustBeNotNilError, "uuidは値が必須です"
|
24
|
+
unless self.steps.is_a?(Array)
|
25
|
+
raise ValidationError, "stepsは配列です"
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class ProconBypassMan::RemoteMacroSender
|
2
2
|
def self.execute(name: , uuid: , steps: )
|
3
3
|
ProconBypassMan.logger.info "[remote macro][sender] name: #{name}, uuid: #{uuid}, steps: #{steps}"
|
4
|
-
ProconBypassMan::QueueOverProcess.push(
|
4
|
+
ProconBypassMan::RemoteMacro::QueueOverProcess.push(
|
5
5
|
ProconBypassMan::RemoteMacro::Task.new(name, uuid, steps)
|
6
6
|
)
|
7
7
|
end
|
@@ -1,13 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
not empty?
|
6
|
-
end
|
1
|
+
class ProconBypassMan::RemoteMacro::TaskQueue < ::Queue
|
2
|
+
def present?
|
3
|
+
not empty?
|
4
|
+
end
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
end
|
6
|
+
def non_blocking_shift
|
7
|
+
present? && shift
|
12
8
|
end
|
13
9
|
end
|
data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb
CHANGED
@@ -10,7 +10,7 @@ module ProconBypassMan
|
|
10
10
|
def execute(to_status: )
|
11
11
|
ProconBypassMan::UpdateRemotePbmActionStatusHttpClient.new(
|
12
12
|
path: path,
|
13
|
-
|
13
|
+
server: ProconBypassMan.config.api_server,
|
14
14
|
).put(to_status: to_status)
|
15
15
|
end
|
16
16
|
|
@@ -1,8 +1,4 @@
|
|
1
|
-
require_relative "io_monitor"
|
2
|
-
|
3
1
|
class ProconBypassMan::Runner
|
4
|
-
class InterruptForRestart < StandardError; end
|
5
|
-
|
6
2
|
include ProconBypassMan::SignalHandler
|
7
3
|
|
8
4
|
def initialize(gadget: , procon: )
|
@@ -24,13 +20,12 @@ class ProconBypassMan::Runner
|
|
24
20
|
|
25
21
|
loop do
|
26
22
|
# NOTE メインプロセスではThreadをいくつか起動しているので念のためパフォーマンスを優先するためにforkしていく
|
27
|
-
child_pid = Kernel.fork
|
23
|
+
child_pid = Kernel.fork do
|
28
24
|
$will_terminate_token = false
|
29
|
-
|
30
|
-
ProconBypassMan::RemoteMacroReceiver.start!
|
25
|
+
ProconBypassMan.after_fork_on_bypass_process
|
31
26
|
ProconBypassMan::BypassCommand.new(gadget: @gadget, procon: @procon).execute # ここでblockingする
|
32
27
|
next
|
33
|
-
|
28
|
+
end
|
34
29
|
|
35
30
|
begin
|
36
31
|
# TODO 子プロセスが消滅した時に、メインプロセスは生き続けてしまい、何もできなくなる問題がある
|
@@ -38,7 +33,7 @@ class ProconBypassMan::Runner
|
|
38
33
|
signal = readable_io.first[0].gets.strip
|
39
34
|
handle_signal(signal)
|
40
35
|
end
|
41
|
-
rescue InterruptForRestart
|
36
|
+
rescue ProconBypassMan::InterruptForRestart
|
42
37
|
ProconBypassMan::PrintMessageCommand.execute(text: "設定ファイルの再読み込みを開始します")
|
43
38
|
Process.kill("USR2", child_pid)
|
44
39
|
Process.wait
|
@@ -68,13 +68,22 @@ module ProconBypassMan
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def self.register_schedules
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
if ProconBypassMan.config.has_api_server?
|
72
|
+
register(
|
73
|
+
schedule: Schedule.new(
|
74
|
+
klass: ProconBypassMan::SyncDeviceStatsJob,
|
75
|
+
args: [->{ ProconBypassMan::DeviceStatus.current }],
|
76
|
+
interval: 60,
|
77
|
+
)
|
76
78
|
)
|
77
|
-
|
79
|
+
register(
|
80
|
+
schedule: Schedule.new(
|
81
|
+
klass: ProconBypassMan::ReportProconPerformanceMeasurementsJob,
|
82
|
+
args: [->{ ProconBypassMan::Procon::PerformanceMeasurement.pop_measurement_collection }],
|
83
|
+
interval: 60,
|
84
|
+
)
|
85
|
+
)
|
86
|
+
end
|
78
87
|
end
|
79
88
|
|
80
89
|
# @param [Schedule] schedule
|
@@ -1,21 +1,15 @@
|
|
1
1
|
module ProconBypassMan
|
2
|
-
module
|
3
|
-
|
4
|
-
attr_accessor :filter, :chain_method
|
5
|
-
def initialize(filter: , chain_method: , block: )
|
6
|
-
@filter = filter
|
7
|
-
@chain_method = chain_method
|
8
|
-
@block = block
|
9
|
-
end
|
10
|
-
end
|
2
|
+
module CallbacksRegisterable
|
3
|
+
attr_accessor :callbacks
|
11
4
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
5
|
+
def register_callback_module(mod)
|
6
|
+
self.callbacks ||= []
|
7
|
+
callbacks << mod
|
8
|
+
self.include(mod)
|
17
9
|
end
|
10
|
+
end
|
18
11
|
|
12
|
+
module Callbacks
|
19
13
|
module ClassMethods
|
20
14
|
def define_callbacks(name)
|
21
15
|
self.singleton_class.attr_accessor "_#{name}_callbacks"
|
@@ -29,8 +23,9 @@ module ProconBypassMan
|
|
29
23
|
end
|
30
24
|
|
31
25
|
def set_callback(kind, filter, chain_method, &block)
|
32
|
-
|
33
|
-
|
26
|
+
self.__callbacks ||= {}
|
27
|
+
self.__callbacks[kind] ||= CallbackChain.new
|
28
|
+
self.__callbacks[kind].append Callback.new(
|
34
29
|
filter: filter,
|
35
30
|
chain_method: chain_method,
|
36
31
|
block: block,
|
@@ -38,33 +33,76 @@ module ProconBypassMan
|
|
38
33
|
end
|
39
34
|
end
|
40
35
|
|
36
|
+
def self.included(mod)
|
37
|
+
mod.singleton_class.attr_accessor :__callbacks
|
38
|
+
mod.extend(ClassMethods)
|
39
|
+
end
|
40
|
+
|
41
|
+
class CallbackChain
|
42
|
+
attr_accessor :callbacks
|
43
|
+
|
44
|
+
def initialize
|
45
|
+
self.callbacks = {}
|
46
|
+
end
|
47
|
+
|
48
|
+
def empty?
|
49
|
+
callbacks.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
def append(callback)
|
53
|
+
self.callbacks[callback.filter] ||= []
|
54
|
+
self.callbacks[callback.filter] << callback
|
55
|
+
end
|
56
|
+
|
57
|
+
def [](filter)
|
58
|
+
self.callbacks[filter]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Callback
|
63
|
+
attr_accessor :filter, :chain_method
|
64
|
+
|
65
|
+
def initialize(filter: , chain_method: , block: )
|
66
|
+
@filter = filter
|
67
|
+
@chain_method = chain_method
|
68
|
+
@block = block
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
41
72
|
# TODO haltしたらcallbackを止める
|
42
|
-
# TODO 複数をチェインできるようにする
|
43
73
|
def run_callbacks(kind, &block)
|
44
|
-
|
45
|
-
|
46
|
-
|
74
|
+
chains = get_callbacks(kind) or raise("unknown callback")
|
75
|
+
if chains.nil? || chains.empty?
|
76
|
+
return block.call
|
77
|
+
end
|
78
|
+
|
79
|
+
chains[:before]&.each do |chain|
|
47
80
|
send chain.chain_method
|
48
|
-
|
49
|
-
|
50
|
-
|
81
|
+
end
|
82
|
+
result = block.call
|
83
|
+
chains[:after]&.each do |chain|
|
51
84
|
send chain.chain_method
|
52
|
-
else
|
53
|
-
raise("unknown filter")
|
54
85
|
end
|
55
|
-
end
|
56
86
|
|
57
|
-
|
58
|
-
|
59
|
-
# end
|
87
|
+
return result
|
88
|
+
end
|
60
89
|
|
61
90
|
def get_callbacks(kind) # :nodoc:
|
62
|
-
|
63
|
-
|
91
|
+
# classに直接moduleをincludeしている場合
|
92
|
+
if defined?(self.class.__callbacks) && !self.class.respond_to?(:callbacks)
|
93
|
+
return self.class.__callbacks[kind.to_sym]
|
94
|
+
end
|
64
95
|
|
65
|
-
|
66
|
-
|
67
|
-
|
96
|
+
list = self.class.callbacks.flat_map { |callback_mod|
|
97
|
+
callback_mod.__callbacks && callback_mod.__callbacks[kind.to_sym]
|
98
|
+
}.compact
|
99
|
+
if(self.class.respond_to?(:__callbacks) && chain = self.class.__callbacks[kind.to_sym])
|
100
|
+
list << chain
|
101
|
+
end
|
102
|
+
table = {}
|
103
|
+
table[:before] = list.flat_map { |x| x[:before] }.compact
|
104
|
+
table[:after] = list.flat_map { |x| x[:after] }.compact
|
105
|
+
table
|
68
106
|
end
|
69
107
|
end
|
70
108
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'drb/drb'
|
2
|
+
|
3
|
+
# NOTE マスタープロセスでstart_distributed_object!をコールする必要がある
|
4
|
+
# forkをしたらそのさきでDRb.start_serviceをコールする必要がある
|
5
|
+
module ProconBypassMan::CanOverProcess
|
6
|
+
PROTOCOL = "drbunix".freeze
|
7
|
+
|
8
|
+
def self.extended(mod)
|
9
|
+
mod.singleton_class.attr_accessor :drb_server, :drb_server_thread
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [void]
|
13
|
+
def start_distributed_object!
|
14
|
+
return unless enable?
|
15
|
+
|
16
|
+
FileUtils.rm_rf(socket_file_path) if File.exist?(socket_file_path)
|
17
|
+
begin
|
18
|
+
self.drb_server = DRb.start_service(socket_path, distributed_class.new, safe_level: 1)
|
19
|
+
rescue Errno::EADDRINUSE => e
|
20
|
+
ProconBypassMan.logger.error e
|
21
|
+
raise
|
22
|
+
end
|
23
|
+
|
24
|
+
self.drb_server_thread =
|
25
|
+
Thread.new do
|
26
|
+
DRb.thread.join
|
27
|
+
end
|
28
|
+
end
|
29
|
+
alias start! start_distributed_object!
|
30
|
+
|
31
|
+
# @return [void]
|
32
|
+
def shutdown_distributed_object
|
33
|
+
if self.drb_server
|
34
|
+
self.drb_server_thread&.kill
|
35
|
+
self.drb_server_thread = nil
|
36
|
+
self.drb_server.stop_service
|
37
|
+
end
|
38
|
+
end
|
39
|
+
alias shutdown shutdown_distributed_object
|
40
|
+
|
41
|
+
# @return [Boolean]
|
42
|
+
def enable?
|
43
|
+
raise NotImplementedError
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [String]
|
47
|
+
def socket_file_path
|
48
|
+
raise NotImplementedError
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [any]
|
52
|
+
def distributed_class
|
53
|
+
raise NotImplementedError
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [String]
|
57
|
+
def socket_path
|
58
|
+
"#{PROTOCOL}:#{socket_file_path}".freeze
|
59
|
+
end
|
60
|
+
end
|
@@ -26,9 +26,9 @@ module ProconBypassMan
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def initialize(path: ,
|
30
|
-
@
|
31
|
-
@uri = URI.parse("#{
|
29
|
+
def initialize(path: , server: , retry_on_connection_error: false)
|
30
|
+
@server = server
|
31
|
+
@uri = URI.parse("#{server}#{path}")
|
32
32
|
@retry_on_connection_error = retry_on_connection_error
|
33
33
|
end
|
34
34
|
|
@@ -76,14 +76,13 @@ module ProconBypassMan
|
|
76
76
|
return response.body
|
77
77
|
end
|
78
78
|
else
|
79
|
-
@server_pool.next!
|
80
79
|
ProconBypassMan.logger.error("#{@uri}から200以外(#{response.code})が帰ってきました. #{response.body}")
|
81
80
|
end
|
82
81
|
end
|
83
82
|
|
84
83
|
def handle_request
|
85
84
|
raise "need block" unless block_given?
|
86
|
-
if @
|
85
|
+
if @server.nil?
|
87
86
|
ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
|
88
87
|
return
|
89
88
|
end
|
@@ -94,6 +93,10 @@ module ProconBypassMan
|
|
94
93
|
sleep(10)
|
95
94
|
retry
|
96
95
|
end
|
96
|
+
rescue Timeout::Error
|
97
|
+
ProconBypassMan.logger.error(e)
|
98
|
+
sleep(10)
|
99
|
+
retry
|
97
100
|
rescue => e
|
98
101
|
puts e
|
99
102
|
ProconBypassMan.logger.error(e)
|
@@ -102,5 +105,5 @@ module ProconBypassMan
|
|
102
105
|
end
|
103
106
|
|
104
107
|
if $0 == __FILE__
|
105
|
-
ProconBypassMan::HttpClient.new(path: '/',
|
108
|
+
ProconBypassMan::HttpClient.new(path: '/', server: nil, retry_on_connection_error: false).get(response_body: '')
|
106
109
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class LoadAgv
|
3
|
+
PATH = '/proc/loadavg'
|
4
|
+
|
5
|
+
# @return [[Integer, Integer, Integer]]
|
6
|
+
def get
|
7
|
+
loadavg = get_proc_loadavg
|
8
|
+
loadavg =~ /^([0-9.]+)\s([0-9.]+)\s([0-9.]+)/
|
9
|
+
return [$1.to_f, $2.to_f, $3.to_f].join("-")
|
10
|
+
rescue Errno::ENOENT
|
11
|
+
""
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def get_proc_loadavg
|
17
|
+
File.read('/proc/loadavg')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class Retryable
|
3
|
+
def self.retryable(tries: , retried: 0, on_no_retry: [])
|
4
|
+
return yield(retried)
|
5
|
+
rescue *on_no_retry
|
6
|
+
raise
|
7
|
+
rescue
|
8
|
+
if tries <= retried
|
9
|
+
raise
|
10
|
+
else
|
11
|
+
retried = retried + 1
|
12
|
+
retry
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -99,11 +99,11 @@ module ProconBypassMan
|
|
99
99
|
def self.validate_and_run_remote_macro(data: )
|
100
100
|
pbm_job_hash = data.dig("message")
|
101
101
|
begin
|
102
|
-
remote_macro_object = ProconBypassMan::RemoteMacroObject.new(name: pbm_job_hash["name"],
|
102
|
+
remote_macro_object = ProconBypassMan::RemoteMacro::RemoteMacroObject.new(name: pbm_job_hash["name"],
|
103
103
|
uuid: pbm_job_hash["uuid"],
|
104
104
|
steps: pbm_job_hash["steps"])
|
105
105
|
remote_macro_object.validate!
|
106
|
-
rescue ProconBypassMan::RemoteMacroObject::ValidationError => e
|
106
|
+
rescue ProconBypassMan::RemoteMacro::RemoteMacroObject::ValidationError => e
|
107
107
|
ProconBypassMan::SendErrorCommand.execute(error: e)
|
108
108
|
return
|
109
109
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class Worker
|
3
|
+
attr_accessor :pid
|
4
|
+
|
5
|
+
def self.run
|
6
|
+
new.run
|
7
|
+
end
|
8
|
+
|
9
|
+
# @param [Boolean]
|
10
|
+
def run
|
11
|
+
return self if @thread
|
12
|
+
@thread = Thread.new do
|
13
|
+
while(item = ProconBypassMan::Background::JobQueue.pop)
|
14
|
+
begin
|
15
|
+
# プロセスを越えるので、文字列でenqueueしてくれる前提. evalしてクラスにする
|
16
|
+
ProconBypassMan::Background::JobPerformer.new(klass: eval(item[:job_class]), args: item[:args]).perform
|
17
|
+
rescue => e
|
18
|
+
ProconBypassMan.logger.error(e)
|
19
|
+
sleep(0.2) # busy loopしないように
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
return self
|
25
|
+
end
|
26
|
+
|
27
|
+
# 重要な非同期ジョブは存在しないのでqueueが捌けるのを待たずにkill
|
28
|
+
def shutdown
|
29
|
+
@thread&.kill
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|