procon_bypass_man 0.1.13 → 0.1.14
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 +3 -0
- data/Gemfile.lock +3 -1
- data/README.md +1 -1
- data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -6
- data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
- data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
- data/lib/procon_bypass_man/background/{job_runnable.rb → jobs/concerns/job_runnable.rb} +0 -0
- data/lib/procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job.rb +29 -0
- data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +5 -3
- data/lib/procon_bypass_man/background/jobs/report_error_job.rb +6 -5
- data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
- data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +5 -4
- data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +7 -10
- data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +5 -4
- data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
- data/lib/procon_bypass_man/background.rb +6 -4
- data/lib/procon_bypass_man/boot_message.rb +4 -0
- data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +0 -4
- data/lib/procon_bypass_man/commands/connect_device_command.rb +6 -1
- data/lib/procon_bypass_man/commands/run_local_shell_command.rb +6 -0
- data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +19 -0
- data/lib/procon_bypass_man/commands/send_error_command.rb +1 -1
- data/lib/procon_bypass_man/commands/write_session_id_command.rb +1 -7
- data/lib/procon_bypass_man/commands.rb +1 -0
- data/lib/procon_bypass_man/configuration.rb +17 -1
- data/lib/procon_bypass_man/device_connector.rb +2 -1
- data/lib/procon_bypass_man/device_status.rb +44 -0
- data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
- data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +21 -0
- data/lib/procon_bypass_man/remote_pbm_action/lib/update_remote_pbm_action_status_command.rb +24 -0
- data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +17 -0
- data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +17 -0
- data/lib/procon_bypass_man/remote_pbm_action.rb +31 -0
- data/lib/procon_bypass_man/scheduler.rb +92 -0
- data/lib/procon_bypass_man/support/http_client.rb +102 -0
- data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
- data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
- data/lib/procon_bypass_man/{background/has_server_pool.rb → support/server_pool.rb} +3 -15
- data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
- data/lib/procon_bypass_man/value_objects/remote_pbm_action_object.rb +38 -0
- data/lib/procon_bypass_man/version.rb +1 -1
- data/lib/procon_bypass_man.rb +30 -5
- data/procon_bypass_man.gemspec +1 -1
- data/project_template/app.rb +1 -1
- data/sig/main.rbs +1 -0
- metadata +39 -7
- data/lib/procon_bypass_man/background/http_client.rb +0 -67
- data/lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 346ad7fa333241bf5464ac38fce07caec0e0a021def6e2d456b7dc49a1f70b0a
|
4
|
+
data.tar.gz: 5f9f6d94706fd00c9ecc738f9626c5a2e6418039997f487f856d2298a6a9df1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 792586a96060eb9adb8e7c0cf31bd56663da6343fa753709158890d47aed1025e87f24f670d176dea543d71cf6de2c6e8bb200b3bf109981f99e0f73b8eaa932
|
7
|
+
data.tar.gz: 8e82db2b88efb8d5752797eab1e203379d30edf6e71fcda3ff35bdba8e46e27923e5da313442be366c50e6c38b8a0583296a36e94c35f078d648fb18f59c2a0d
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
procon_bypass_man (0.1.
|
4
|
+
procon_bypass_man (0.1.14)
|
5
|
+
pbmenv
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -30,6 +31,7 @@ GEM
|
|
30
31
|
parallel (1.21.0)
|
31
32
|
parser (3.0.2.0)
|
32
33
|
ast (~> 2.4.1)
|
34
|
+
pbmenv (0.1.5)
|
33
35
|
pry (0.14.1)
|
34
36
|
coderay (~> 1.1)
|
35
37
|
method_source (~> 1.0)
|
data/README.md
CHANGED
@@ -67,7 +67,7 @@ sudo kill -USR2 `cat ./pbm_pid`
|
|
67
67
|
```
|
68
68
|
|
69
69
|
### 起動ログをサーバに送信する
|
70
|
-
* `ProconBypassMan.
|
70
|
+
* `ProconBypassMan.api_servers = "http://.."` を設定すると、 `POST /api/events` に対して起動ログなどを送信するようになります
|
71
71
|
|
72
72
|
### 開発環境でログの送信を確認する方法
|
73
73
|
* `bundle exec bin/dev_api_server.rb`
|
@@ -1,12 +1,7 @@
|
|
1
1
|
class ProconBypassMan::BaseJob
|
2
|
-
extend ProconBypassMan::Background::HasServerPool
|
3
2
|
extend ProconBypassMan::Background::JobRunnable
|
4
3
|
|
5
4
|
def self.servers
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.path
|
10
|
-
"/api/events"
|
5
|
+
raise NotImplementedError
|
11
6
|
end
|
12
7
|
end
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class ProconBypassMan::FetchAndRunRemotePbmActionJob < ProconBypassMan::BaseJob
|
2
|
+
extend ProconBypassMan::HasExternalApiSetting
|
3
|
+
|
4
|
+
def self.perform
|
5
|
+
pbm_jobs = ProconBypassMan::HttpClient.new(path: path, server_pool: server_pool).get
|
6
|
+
if pbm_jobs.nil? || pbm_jobs.size.zero?
|
7
|
+
# ProconBypassMan.logger.debug "remote pbm_jobsはありませんでした"
|
8
|
+
return
|
9
|
+
else
|
10
|
+
pbm_job_hash = pbm_jobs.first
|
11
|
+
begin
|
12
|
+
pbm_job_object = ProconBypassMan::RemotePbmActionObject.new(action: pbm_job_hash["action"],
|
13
|
+
status: pbm_job_hash["status"],
|
14
|
+
uuid: pbm_job_hash["uuid"],
|
15
|
+
created_at: pbm_job_hash["created_at"],
|
16
|
+
job_args: pbm_job_hash["args"])
|
17
|
+
pbm_job_object.validate!
|
18
|
+
ProconBypassMan::RunRemotePbmActionDispatchCommand.execute(action: pbm_job_object.action, uuid: pbm_job_object.uuid, job_args: pbm_job_object.job_args)
|
19
|
+
rescue ProconBypassMan::RemotePbmActionObject::ValidationError => e
|
20
|
+
ProconBypassMan::SendErrorCommand.execute(error: e)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.path
|
26
|
+
device_id = ProconBypassMan.device_id
|
27
|
+
"/api/devices/#{device_id}/pbm_jobs"
|
28
|
+
end
|
29
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
class ProconBypassMan::ReportBootJob <
|
1
|
+
class ProconBypassMan::ReportBootJob < ProconBypassMan::ReportEventBaseJob
|
2
|
+
extend ProconBypassMan::HasExternalApiSetting
|
3
|
+
|
2
4
|
# @param [String] body
|
3
5
|
def self.perform(body)
|
4
|
-
ProconBypassMan::
|
6
|
+
ProconBypassMan::ReportHttpClient.new(
|
5
7
|
path: path,
|
6
|
-
|
8
|
+
server_pool: server_pool,
|
7
9
|
retry_on_connection_error: true,
|
8
10
|
).post(body: body, event_type: :boot)
|
9
11
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
class ProconBypassMan::ReportErrorJob < ProconBypassMan::
|
1
|
+
class ProconBypassMan::ReportErrorJob < ProconBypassMan::ReportEventBaseJob
|
2
|
+
extend ProconBypassMan::HasExternalApiSetting
|
3
|
+
|
2
4
|
# @param [String] body
|
3
5
|
def self.perform(body)
|
4
|
-
ProconBypassMan::
|
6
|
+
ProconBypassMan::ReportHttpClient.new(
|
5
7
|
path: path,
|
6
|
-
|
7
|
-
|
8
|
-
).post(body: body, event_type: :error,)
|
8
|
+
server_pool: server_pool,
|
9
|
+
).post(body: body, event_type: :error)
|
9
10
|
end
|
10
11
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
class ProconBypassMan::ReportLoadConfigJob <
|
1
|
+
class ProconBypassMan::ReportLoadConfigJob < ProconBypassMan::ReportEventBaseJob
|
2
|
+
extend ProconBypassMan::HasExternalApiSetting
|
3
|
+
|
2
4
|
# @param [String] body
|
3
5
|
def self.perform(body)
|
4
|
-
ProconBypassMan::
|
6
|
+
ProconBypassMan::ReportHttpClient.new(
|
5
7
|
path: path,
|
6
|
-
|
7
|
-
retry_on_connection_error: false,
|
8
|
+
server_pool: server_pool,
|
8
9
|
).post(body: body, event_type: :load_config)
|
9
10
|
end
|
10
11
|
end
|
@@ -1,18 +1,15 @@
|
|
1
|
-
class ProconBypassMan::ReportPressedButtonsJob
|
2
|
-
extend ProconBypassMan::
|
3
|
-
extend ProconBypassMan::Background::JobRunnable
|
4
|
-
|
5
|
-
PATH = "/api/pressed_buttons"
|
1
|
+
class ProconBypassMan::ReportPressedButtonsJob < ProconBypassMan::BaseJob
|
2
|
+
extend ProconBypassMan::HasInternalApiSetting
|
6
3
|
|
7
4
|
# @param [String] body
|
8
5
|
def self.perform(body)
|
9
|
-
ProconBypassMan::
|
10
|
-
path:
|
11
|
-
|
6
|
+
ProconBypassMan::ReportHttpClient.new(
|
7
|
+
path: path,
|
8
|
+
server_pool: server_pool,
|
12
9
|
).post(body: body, event_type: :internal)
|
13
10
|
end
|
14
11
|
|
15
|
-
def self.
|
16
|
-
|
12
|
+
def self.path
|
13
|
+
"/api/pressed_buttons"
|
17
14
|
end
|
18
15
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
class ProconBypassMan::ReportReloadConfigJob <
|
1
|
+
class ProconBypassMan::ReportReloadConfigJob < ProconBypassMan::ReportEventBaseJob
|
2
|
+
extend ProconBypassMan::HasExternalApiSetting
|
3
|
+
|
2
4
|
# @param [String] body
|
3
5
|
def self.perform(body)
|
4
|
-
ProconBypassMan::
|
6
|
+
ProconBypassMan::ReportHttpClient.new(
|
5
7
|
path: path,
|
6
|
-
|
7
|
-
retry_on_connection_error: false,
|
8
|
+
server_pool: server_pool,
|
8
9
|
).post(body: body, event_type: :reload_config)
|
9
10
|
end
|
10
11
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ProconBypassMan::SyncDeviceStatsJob < ProconBypassMan::BaseJob
|
2
|
+
extend ProconBypassMan::HasExternalApiSetting
|
3
|
+
|
4
|
+
# @param [Symbol] status
|
5
|
+
def self.perform(status)
|
6
|
+
ProconBypassMan::SendDeviceStatsHttpClient.new(
|
7
|
+
path: path,
|
8
|
+
server_pool: server_pool,
|
9
|
+
).post(status: status, pbm_session_id: ProconBypassMan.session_id)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.path
|
13
|
+
device_id = ProconBypassMan.device_id
|
14
|
+
"/api/devices/#{ProconBypassMan.device_id}/device_statuses"
|
15
|
+
end
|
16
|
+
end
|
@@ -1,12 +1,14 @@
|
|
1
|
-
require "procon_bypass_man/background/
|
1
|
+
require "procon_bypass_man/background/jobs/concerns/has_internal_api_setting"
|
2
|
+
require "procon_bypass_man/background/jobs/concerns/has_external_api_setting"
|
3
|
+
require "procon_bypass_man/background/jobs/concerns/job_runnable"
|
2
4
|
require "procon_bypass_man/background/job_runner"
|
3
5
|
require "procon_bypass_man/background/job_performer"
|
4
|
-
require "procon_bypass_man/background/has_server_pool"
|
5
|
-
require "procon_bypass_man/background/http_client"
|
6
6
|
require "procon_bypass_man/background/jobs/base_job"
|
7
|
+
require "procon_bypass_man/background/jobs/report_event_base_job"
|
7
8
|
require "procon_bypass_man/background/jobs/report_boot_job"
|
8
9
|
require "procon_bypass_man/background/jobs/report_reload_config_job"
|
9
10
|
require "procon_bypass_man/background/jobs/report_load_config_job"
|
10
11
|
require "procon_bypass_man/background/jobs/report_error_job"
|
11
|
-
require "procon_bypass_man/background/jobs/report_heartbeat_job"
|
12
12
|
require "procon_bypass_man/background/jobs/report_pressed_buttons_job"
|
13
|
+
require "procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job"
|
14
|
+
require "procon_bypass_man/background/jobs/sync_device_stats_job"
|
@@ -9,6 +9,8 @@ class ProconBypassMan::BootMessage
|
|
9
9
|
@table[:setting_path] = ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path
|
10
10
|
@table[:uptime_from_boot] = ProconBypassMan::Uptime.from_boot
|
11
11
|
@table[:use_pbmenv] = !(!!`which pbmenv`.empty?)
|
12
|
+
@table[:session_id] = ProconBypassMan.session_id
|
13
|
+
@table[:device_id] = ProconBypassMan.device_id
|
12
14
|
|
13
15
|
# 開発中のHEADを取りたかったけど、Gem::Specification経由から取得する必要がありそう
|
14
16
|
# build_version = `git rev-parse --short HEAD`.chomp
|
@@ -33,6 +35,8 @@ class ProconBypassMan::BootMessage
|
|
33
35
|
setting_path: #{@table[:setting_path]}
|
34
36
|
uptime from boot: #{@table[:uptime_from_boot]} sec
|
35
37
|
use_pbmenv: #{@table[:use_pbmenv]}
|
38
|
+
session_id: #{ProconBypassMan.session_id}
|
39
|
+
device_id: #{ProconBypassMan.device_id}
|
36
40
|
----
|
37
41
|
EOF
|
38
42
|
end
|
@@ -33,10 +33,6 @@ class ProconBypassMan::Bypass
|
|
33
33
|
ProconBypassMan::ProconReader.new(binary: bypass_value.binary).to_hash
|
34
34
|
)
|
35
35
|
end
|
36
|
-
|
37
|
-
ProconBypassMan.cache.fetch key: 'heartbeat_reporter', expires_in: 60 do
|
38
|
-
ProconBypassMan::ReportHeartbeatJob.perform_async(ProconBypassMan::BootMessage.new.to_hash)
|
39
|
-
end
|
40
36
|
end
|
41
37
|
end
|
42
38
|
end
|
@@ -2,8 +2,13 @@ class ProconBypassMan::ConnectDeviceCommand
|
|
2
2
|
# @return [void]
|
3
3
|
def self.execute!
|
4
4
|
gadget, procon = ProconBypassMan::DeviceConnector.connect
|
5
|
+
rescue ProconBypassMan::DeviceConnector::NotFoundProconError => e
|
6
|
+
ProconBypassMan.logger.error e
|
7
|
+
gadget&.close
|
8
|
+
procon&.close
|
9
|
+
raise ProconBypassMan::NotFoundProconError
|
5
10
|
rescue ProconBypassMan::SafeTimeout::Timeout
|
6
|
-
|
11
|
+
ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
|
7
12
|
gadget&.close
|
8
13
|
procon&.close
|
9
14
|
raise ::ProconBypassMan::EternalConnectionError
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ProconBypassMan::RunRemotePbmActionDispatchCommand
|
2
|
+
# @param [String] action
|
3
|
+
# @param [String] uuid
|
4
|
+
# @return [void]
|
5
|
+
def self.execute(action: , uuid: , job_args: )
|
6
|
+
case action
|
7
|
+
when ProconBypassMan::RemotePbmAction::ACTION_CHANGE_PBM_VERSION
|
8
|
+
ProconBypassMan::RemotePbmAction::ChangePbmVersionAction.new(pbm_job_uuid: uuid).run!(job_args: job_args)
|
9
|
+
when ProconBypassMan::RemotePbmAction::ACTION_STOP_PBM
|
10
|
+
ProconBypassMan::RemotePbmAction::StopPbmAction.new(pbm_job_uuid: uuid).run!(job_args: {})
|
11
|
+
when ProconBypassMan::RemotePbmAction::ACTION_REBOOT_OS
|
12
|
+
ProconBypassMan::RemotePbmAction::RebootOsAction.new(pbm_job_uuid: uuid).run!(job_args: {})
|
13
|
+
else
|
14
|
+
ProconBypassMan::SendErrorCommand.execute(error: "#{action}は対応していないアクションです")
|
15
|
+
end
|
16
|
+
rescue ProconBypassMan::RemotePbmAction::ActionUnexpectedError => e
|
17
|
+
ProconBypassMan::SendErrorCommand.execute(error: e)
|
18
|
+
end
|
19
|
+
end
|
@@ -2,12 +2,6 @@ class ProconBypassMan::WriteSessionIdCommand
|
|
2
2
|
# @return [String] session_id ラズパイが起動してからshutdownするまで同じ文字列を返す
|
3
3
|
# 起動すると/tmp がなくなる前提の実装
|
4
4
|
def self.execute
|
5
|
-
|
6
|
-
if(sid = File.read(path))
|
7
|
-
return sid
|
8
|
-
end
|
9
|
-
rescue Errno::ENOENT
|
10
|
-
File.write(path, "s_#{SecureRandom.uuid}")
|
11
|
-
return SecureRandom.uuid
|
5
|
+
@@session_id ||= "s_#{SecureRandom.uuid}"
|
12
6
|
end
|
13
7
|
end
|
@@ -5,3 +5,4 @@ require "procon_bypass_man/commands/send_reload_config_event_command"
|
|
5
5
|
require "procon_bypass_man/commands/send_error_command"
|
6
6
|
require "procon_bypass_man/commands/connect_device_command"
|
7
7
|
require "procon_bypass_man/commands/bypass_command"
|
8
|
+
require "procon_bypass_man/commands/run_remote_pbm_action_dispatch_command"
|
@@ -16,6 +16,11 @@ class ProconBypassMan::Configuration
|
|
16
16
|
@@pid_path ||= File.expand_path("#{root}/pbm_pid", __dir__).freeze
|
17
17
|
end
|
18
18
|
|
19
|
+
# @return [Integer]
|
20
|
+
def pid
|
21
|
+
File.read(pid_path).to_i
|
22
|
+
end
|
23
|
+
|
19
24
|
def digest_path
|
20
25
|
config.digest_path
|
21
26
|
end
|
@@ -31,7 +36,7 @@ class ProconBypassMan::Configuration
|
|
31
36
|
|
32
37
|
# @return [String]
|
33
38
|
def device_id
|
34
|
-
ProconBypassMan::WriteDeviceIdCommand.execute
|
39
|
+
ENV["DEBUG_DEVICE_ID"] || ProconBypassMan::WriteDeviceIdCommand.execute
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
@@ -96,6 +101,17 @@ class ProconBypassMan::Configuration
|
|
96
101
|
end
|
97
102
|
end
|
98
103
|
|
104
|
+
# @return [Array<ProconBypassMan::ServerPool>]
|
105
|
+
def internal_server_pool
|
106
|
+
@internal_server_pool ||= ProconBypassMan::ServerPool.new(servers: internal_api_servers)
|
107
|
+
end
|
108
|
+
|
109
|
+
# @return [Array<ProconBypassMan::ServerPool>]
|
110
|
+
def server_pool
|
111
|
+
@server_pool ||= ProconBypassMan::ServerPool.new(servers: api_servers)
|
112
|
+
end
|
113
|
+
|
114
|
+
# @return [Array<String>]
|
99
115
|
def api_servers
|
100
116
|
if !!ENV["API_SERVER"]
|
101
117
|
[ENV["API_SERVER"]].reject(&:nil?)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class ProconBypassMan::DeviceConnector
|
2
2
|
class BytesMismatchError < StandardError; end
|
3
|
+
class NotFoundProconError < StandardError; end
|
3
4
|
|
4
5
|
class Value
|
5
6
|
attr_accessor :read_from, :values
|
@@ -300,7 +301,7 @@ class ProconBypassMan::DeviceConnector
|
|
300
301
|
@procon = File.open(PROCON2_PATH, "w+b")
|
301
302
|
@gadget = File.open('/dev/hidg0', "w+b")
|
302
303
|
else
|
303
|
-
raise "/dev/hidraw0, /dev/hidraw1の両方見つかりませんでした"
|
304
|
+
raise NotFoundProconError, "/dev/hidraw0, /dev/hidraw1の両方見つかりませんでした"
|
304
305
|
end
|
305
306
|
system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
|
306
307
|
system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class ProconBypassMan::DeviceStatus
|
2
|
+
INITIALIZED = :initialized
|
3
|
+
RUNNING = :running
|
4
|
+
CONNECTED_BUT_SLEEPING = :connected_but_sleeping # コードはつながっているが、switchがsleepしているとき
|
5
|
+
PROCON_NOT_FOUND_ERROR = :procon_not_found_error # 繋がっていないとか、デバイスが使えない時
|
6
|
+
CONNECTED_BUT_ERROR = :connected_but_error # 実行時エラーあたり
|
7
|
+
SETTING_SYNTAX_ERROR_AND_SHUTDOWN = :setting_syntax_error_and_shutdown
|
8
|
+
|
9
|
+
@@status = nil
|
10
|
+
|
11
|
+
def self.current
|
12
|
+
@@status || INITIALIZED
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.change_to_running!
|
16
|
+
@@status = RUNNING
|
17
|
+
ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.change_to_connected_but_sleeping!
|
21
|
+
@@status = CONNECTED_BUT_SLEEPING
|
22
|
+
ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.change_to_procon_not_found_error!
|
26
|
+
@@status = PROCON_NOT_FOUND_ERROR
|
27
|
+
ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.change_to_device_error!
|
31
|
+
@@status = DEVICE_ERROR
|
32
|
+
ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.change_to_connected_but_error!
|
36
|
+
@@status = CONNECTED_BUT_ERROR
|
37
|
+
ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.change_to_setting_syntax_error_and_shutdown!
|
41
|
+
@@status = SETTING_SYNTAX_ERROR_AND_SHUTDOWN
|
42
|
+
ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class ActionUnexpectedError < StandardError; end
|
4
|
+
class NeedPbmVersionError < ActionUnexpectedError; end
|
5
|
+
|
6
|
+
class BaseAction
|
7
|
+
attr_accessor :pbm_job_uuid
|
8
|
+
|
9
|
+
# @param [String] pbm_job_uuid
|
10
|
+
def initialize(pbm_job_uuid: )
|
11
|
+
self.pbm_job_uuid = pbm_job_uuid
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [void]
|
15
|
+
def action_content(_args)
|
16
|
+
raise NotImplementedError, nil
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param [Hash] args
|
20
|
+
# @return [void]
|
21
|
+
def run!(job_args: )
|
22
|
+
before_action_callback
|
23
|
+
action_content(args: job_args)
|
24
|
+
after_action_callback
|
25
|
+
rescue => e
|
26
|
+
be_failed
|
27
|
+
ProconBypassMan::SendErrorCommand.execute(error: e)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# @return [void]
|
33
|
+
def before_action_callback; end
|
34
|
+
# @return [void]
|
35
|
+
def after_action_callback; end
|
36
|
+
|
37
|
+
# @return [void]
|
38
|
+
def be_failed
|
39
|
+
ProconBypassMan::UpdateRemotePbmActionStatusCommand.new(pbm_job_uuid: pbm_job_uuid).execute(to_status: :failed)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [void]
|
43
|
+
def be_in_progress
|
44
|
+
ProconBypassMan::UpdateRemotePbmActionStatusCommand.new(pbm_job_uuid: pbm_job_uuid).execute(to_status: :in_progress)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [void]
|
48
|
+
def be_processed
|
49
|
+
ProconBypassMan::UpdateRemotePbmActionStatusCommand.new(pbm_job_uuid: pbm_job_uuid).execute(to_status: :processed)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class ChangePbmVersionAction < BaseAction
|
4
|
+
|
5
|
+
def action_content(args: )
|
6
|
+
require "pbmenv"
|
7
|
+
ProconBypassMan.logger.info "execute ChangePbmVersionAction!"
|
8
|
+
pbm_version = args["pbm_version"] or raise(ProconBypassMan::RemotePbmAction::NeedPbmVersionError, "pbm_versionが必要です, #{args.inspect}")
|
9
|
+
Pbmenv.install(pbm_version)
|
10
|
+
Pbmenv.use(pbm_version)
|
11
|
+
`reboot` # symlinkの参照先が変わるのでrebootする必要がある
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def before_action_callback
|
17
|
+
be_processed
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class UpdateRemotePbmActionStatusCommand
|
3
|
+
# @param [String] pbm_job_uuid
|
4
|
+
def initialize(pbm_job_uuid: )
|
5
|
+
@pbm_job_uuid = pbm_job_uuid
|
6
|
+
end
|
7
|
+
|
8
|
+
# @param [String] to_status
|
9
|
+
# @return [void]
|
10
|
+
def execute(to_status: )
|
11
|
+
ProconBypassMan::UpdateRemotePbmActionStatusHttpClient.new(
|
12
|
+
path: path,
|
13
|
+
server_pool: ProconBypassMan.config.server_pool,
|
14
|
+
).put(to_status: to_status)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# @return [String]
|
20
|
+
def path
|
21
|
+
"/api/devices/#{ProconBypassMan.device_id}/pbm_jobs/#{@pbm_job_uuid}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class RebootOsAction < BaseAction
|
4
|
+
|
5
|
+
def action_content(_args)
|
6
|
+
ProconBypassMan.logger.info "execute RebootOsAction!"
|
7
|
+
`reboot`
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def before_action_callback
|
13
|
+
be_processed
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class StopPbmAction < BaseAction
|
4
|
+
|
5
|
+
def action_content(_args)
|
6
|
+
ProconBypassMan.logger.info "execute StopPbmAction!"
|
7
|
+
Process.kill("TERM", ProconBypassMan.pid)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def before_action_callback
|
13
|
+
be_processed
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
require "procon_bypass_man/remote_pbm_action/base_action"
|
4
|
+
require "procon_bypass_man/remote_pbm_action/change_pbm_version_action"
|
5
|
+
require "procon_bypass_man/remote_pbm_action/reboot_os_action"
|
6
|
+
require "procon_bypass_man/remote_pbm_action/stop_pbm_action"
|
7
|
+
require "procon_bypass_man/remote_pbm_action/lib/update_remote_pbm_action_status_command"
|
8
|
+
|
9
|
+
ACTION_CHANGE_PBM_VERSION = "change_pbm_version"
|
10
|
+
ACTION_REBOOT_OS = "reboot_os"
|
11
|
+
ACTION_STOP_PBM = "stop_pbm"
|
12
|
+
ACTION_RESTORE_SETTING = "restore_setting" # TODO
|
13
|
+
|
14
|
+
ACTIONS = [
|
15
|
+
ACTION_CHANGE_PBM_VERSION,
|
16
|
+
ACTION_REBOOT_OS,
|
17
|
+
ACTION_STOP_PBM,
|
18
|
+
ACTION_RESTORE_SETTING,
|
19
|
+
]
|
20
|
+
|
21
|
+
STATUS_FAILED = :failed
|
22
|
+
STATUS_IN_PROGRESS = :in_progress
|
23
|
+
STATUS_PROCESSED = :processed
|
24
|
+
|
25
|
+
ACTION_STATUSES = [
|
26
|
+
STATUS_FAILED,
|
27
|
+
STATUS_IN_PROGRESS,
|
28
|
+
STATUS_PROCESSED,
|
29
|
+
]
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class Scheduler
|
3
|
+
class Schedule
|
4
|
+
attr_accessor :klass, :args, :interval, :next_enqueue_at
|
5
|
+
|
6
|
+
# @param [any] klass
|
7
|
+
# @param [Array] args
|
8
|
+
# @param [Integer] interval
|
9
|
+
def initialize(klass: , args: , interval: )
|
10
|
+
self.klass = klass
|
11
|
+
self.args = args
|
12
|
+
self.interval = interval
|
13
|
+
self.next_enqueue_at = Time.now
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [void]
|
17
|
+
def enqueue
|
18
|
+
klass.perform_async(*unwrap_args(args))
|
19
|
+
set_next_enqueue_at!
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [boolean]
|
23
|
+
def past_interval?
|
24
|
+
next_enqueue_at < Time.now
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# @return [void]
|
30
|
+
def set_next_enqueue_at!
|
31
|
+
self.next_enqueue_at = Time.now + interval
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [Array] args
|
35
|
+
# @return [void]
|
36
|
+
def unwrap_args(args)
|
37
|
+
args.map do |arg|
|
38
|
+
case arg
|
39
|
+
when Proc
|
40
|
+
arg.call
|
41
|
+
else
|
42
|
+
arg
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Hash]
|
49
|
+
def self.schedules
|
50
|
+
@@schedules
|
51
|
+
end
|
52
|
+
|
53
|
+
@@schedules = {}
|
54
|
+
|
55
|
+
def self.start!
|
56
|
+
register_schedules
|
57
|
+
|
58
|
+
@@thread = Thread.start do
|
59
|
+
loop do
|
60
|
+
schedules.each do |_key, schedule|
|
61
|
+
if schedule.past_interval?
|
62
|
+
schedule.enqueue
|
63
|
+
end
|
64
|
+
end
|
65
|
+
sleep 10
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.register_schedules
|
71
|
+
register(
|
72
|
+
schedule: Schedule.new(
|
73
|
+
klass: ProconBypassMan::FetchAndRunRemotePbmActionJob,
|
74
|
+
args: [],
|
75
|
+
interval: 3,
|
76
|
+
)
|
77
|
+
)
|
78
|
+
register(
|
79
|
+
schedule: Schedule.new(
|
80
|
+
klass: ProconBypassMan::SyncDeviceStatsJob,
|
81
|
+
args: [->{ ProconBypassMan::DeviceStatus.current }],
|
82
|
+
interval: 60,
|
83
|
+
)
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
# @param [Schedule] schedule
|
88
|
+
def self.register(schedule: )
|
89
|
+
schedules[schedule.klass] = schedule
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class HttpClient
|
3
|
+
class HttpRequest
|
4
|
+
class Get
|
5
|
+
def self.request!(uri: )
|
6
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
7
|
+
http.use_ssl = uri.scheme === "https"
|
8
|
+
http.get(uri.path, { "Content-Type" => "application/json" })
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Post
|
13
|
+
def self.request!(uri: , request_body: {})
|
14
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
15
|
+
http.use_ssl = uri.scheme === "https"
|
16
|
+
http.post(uri.path, request_body.to_json, { "Content-Type" => "application/json" })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Put
|
21
|
+
def self.request!(uri: , request_body: {})
|
22
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
23
|
+
http.use_ssl = uri.scheme === "https"
|
24
|
+
http.put(uri.path, request_body.to_json, { "Content-Type" => "application/json" })
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(path: , server_pool: , retry_on_connection_error: false)
|
30
|
+
@server_pool = server_pool
|
31
|
+
@uri = URI.parse("#{server_pool.server}#{path}")
|
32
|
+
@retry_on_connection_error = retry_on_connection_error
|
33
|
+
end
|
34
|
+
|
35
|
+
def get
|
36
|
+
handle_request do
|
37
|
+
response = HttpRequest::Get.request!(
|
38
|
+
uri: @uri,
|
39
|
+
)
|
40
|
+
break process_response(response)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def post(request_body: )
|
45
|
+
handle_request do
|
46
|
+
body = {}.merge!(request_body)
|
47
|
+
response = HttpRequest::Post.request!(
|
48
|
+
uri: @uri,
|
49
|
+
request_body: body,
|
50
|
+
)
|
51
|
+
break process_response(response)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def put(request_body: )
|
56
|
+
handle_request do
|
57
|
+
body = {
|
58
|
+
hostname: `hostname`.chomp,
|
59
|
+
}.merge!(request_body)
|
60
|
+
response = HttpRequest::Put.request!(
|
61
|
+
uri: @uri,
|
62
|
+
request_body: body,
|
63
|
+
)
|
64
|
+
break process_response(response)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def process_response(response)
|
71
|
+
case response.code
|
72
|
+
when /^200/
|
73
|
+
begin
|
74
|
+
return JSON.parse(response.body)
|
75
|
+
rescue JSON::ParserError
|
76
|
+
return response.body
|
77
|
+
end
|
78
|
+
else
|
79
|
+
@server_pool.next!
|
80
|
+
ProconBypassMan.logger.error("#{@uri}から200以外(#{response.code})が帰ってきました. #{response.body}")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def handle_request
|
85
|
+
raise "need block" unless block_given?
|
86
|
+
if @server_pool.server.nil?
|
87
|
+
ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
|
88
|
+
return
|
89
|
+
end
|
90
|
+
return yield
|
91
|
+
rescue SocketError => e
|
92
|
+
ProconBypassMan.logger.error(e)
|
93
|
+
if @retry_on_connection_error
|
94
|
+
sleep(10)
|
95
|
+
retry
|
96
|
+
end
|
97
|
+
rescue => e
|
98
|
+
puts e
|
99
|
+
ProconBypassMan.logger.error(e)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class ReportHttpClient < HttpClient
|
3
|
+
def post(body: , event_type: )
|
4
|
+
if body.is_a?(String)
|
5
|
+
b = { text: body }
|
6
|
+
else
|
7
|
+
b = body
|
8
|
+
end
|
9
|
+
|
10
|
+
super(request_body: {
|
11
|
+
session_id: ProconBypassMan.session_id,
|
12
|
+
device_id: ProconBypassMan.device_id,
|
13
|
+
hostname: `hostname`.chomp,
|
14
|
+
event_type: event_type,
|
15
|
+
body: b,
|
16
|
+
})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module ProconBypassMan
|
1
|
+
module ProconBypassMan
|
2
2
|
class ServerPool
|
3
3
|
def initialize(servers: )
|
4
4
|
if servers.nil? || servers.empty?
|
@@ -29,6 +29,8 @@ module ProconBypassMan::Background::HasServerPool
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
private
|
33
|
+
|
32
34
|
def reset
|
33
35
|
@index = 0
|
34
36
|
end
|
@@ -37,18 +39,4 @@ module ProconBypassMan::Background::HasServerPool
|
|
37
39
|
@index = @index + 1
|
38
40
|
end
|
39
41
|
end
|
40
|
-
|
41
|
-
def reset_server_pool!
|
42
|
-
@pool_server = nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def pool_server
|
46
|
-
@pool_server ||= ServerPool.new(
|
47
|
-
servers: servers
|
48
|
-
)
|
49
|
-
end
|
50
|
-
|
51
|
-
def servers
|
52
|
-
raise NotImplementedError, nil
|
53
|
-
end
|
54
42
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class RemotePbmActionObject
|
3
|
+
# valueobjectがvalidatorの責務も持っている. 今度分離する
|
4
|
+
class ValidationError < StandardError; end
|
5
|
+
class MustBeNotNilError < ValidationError; end
|
6
|
+
class NonSupportAction < ValidationError; end
|
7
|
+
|
8
|
+
attr_accessor :action, :status, :uuid, :created_at, :job_args
|
9
|
+
|
10
|
+
# @param [String] action
|
11
|
+
# @param [String] status
|
12
|
+
# @param [String] #uuid
|
13
|
+
# @param [Time] created_at
|
14
|
+
# @return [Hash] job_args
|
15
|
+
def initialize(action: , status:, uuid:, created_at:, job_args: )
|
16
|
+
self.action = action
|
17
|
+
self.status = status
|
18
|
+
self.uuid = uuid
|
19
|
+
self.created_at = created_at
|
20
|
+
self.job_args = job_args
|
21
|
+
|
22
|
+
freeze
|
23
|
+
end
|
24
|
+
|
25
|
+
# @raise [MustBeNotNilError]
|
26
|
+
# @raise [NonSupportAction]
|
27
|
+
# @return [void]
|
28
|
+
def validate!
|
29
|
+
self.action or raise MustBeNotNilError, "actionは値が必須です"
|
30
|
+
self.status or raise MustBeNotNilError, "statusは値が必須です"
|
31
|
+
self.uuid or raise MustBeNotNilError, "uuidは値が必須です"
|
32
|
+
|
33
|
+
unless ProconBypassMan::RemotePbmAction::ACTIONS.include?(action)
|
34
|
+
raise NonSupportAction, "知らないアクションです"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/procon_bypass_man.rb
CHANGED
@@ -6,16 +6,23 @@ require "fileutils"
|
|
6
6
|
require "securerandom"
|
7
7
|
|
8
8
|
require_relative "procon_bypass_man/version"
|
9
|
+
require_relative "procon_bypass_man/remote_pbm_action"
|
9
10
|
require_relative "procon_bypass_man/support/signal_handler"
|
10
11
|
require_relative "procon_bypass_man/support/callbacks"
|
11
12
|
require_relative "procon_bypass_man/support/safe_timeout"
|
12
13
|
require_relative "procon_bypass_man/support/compress_array"
|
13
14
|
require_relative "procon_bypass_man/support/uptime"
|
14
15
|
require_relative "procon_bypass_man/support/on_memory_cache"
|
16
|
+
require_relative "procon_bypass_man/support/http_client"
|
17
|
+
require_relative "procon_bypass_man/support/report_http_client"
|
18
|
+
require_relative "procon_bypass_man/support/update_remote_pbm_action_status_http_client"
|
19
|
+
require_relative "procon_bypass_man/support/send_device_stats_http_client"
|
20
|
+
require_relative "procon_bypass_man/support/server_pool"
|
15
21
|
require_relative "procon_bypass_man/background"
|
16
22
|
require_relative "procon_bypass_man/commands"
|
17
23
|
require_relative "procon_bypass_man/bypass"
|
18
24
|
require_relative "procon_bypass_man/device_connector"
|
25
|
+
require_relative "procon_bypass_man/device_status"
|
19
26
|
require_relative "procon_bypass_man/runner"
|
20
27
|
require_relative "procon_bypass_man/processor"
|
21
28
|
require_relative "procon_bypass_man/configuration"
|
@@ -24,6 +31,8 @@ require_relative "procon_bypass_man/procon"
|
|
24
31
|
require_relative "procon_bypass_man/procon_reader"
|
25
32
|
require_relative "procon_bypass_man/procon/analog_stick"
|
26
33
|
require_relative "procon_bypass_man/procon/analog_stick_cap"
|
34
|
+
require_relative "procon_bypass_man/value_objects/remote_pbm_action_object"
|
35
|
+
require_relative "procon_bypass_man/scheduler"
|
27
36
|
require_relative "procon_bypass_man/splatoon2"
|
28
37
|
|
29
38
|
STDOUT.sync = true
|
@@ -34,6 +43,7 @@ module ProconBypassMan
|
|
34
43
|
|
35
44
|
class CouldNotLoadConfigError < StandardError; end
|
36
45
|
class FirstConnectionError < StandardError; end
|
46
|
+
class NotFoundProconError < StandardError; end
|
37
47
|
class EternalConnectionError < StandardError; end
|
38
48
|
|
39
49
|
def self.buttons_setting_configure(setting_path: nil, &block)
|
@@ -50,25 +60,36 @@ module ProconBypassMan
|
|
50
60
|
|
51
61
|
# @return [void]
|
52
62
|
def self.run(setting_path: nil, &block)
|
63
|
+
ProconBypassMan::Scheduler.start!
|
64
|
+
ProconBypassMan::Background::JobRunner.start!
|
65
|
+
|
53
66
|
ProconBypassMan.logger.info "PBMを起動しています"
|
54
67
|
puts "PBMを起動しています"
|
55
68
|
buttons_setting_configure(setting_path: setting_path, &block)
|
56
69
|
initialize_pbm
|
57
70
|
File.write(pid_path, $$)
|
58
71
|
ProconBypassMan::WriteSessionIdCommand.execute
|
59
|
-
ProconBypassMan::Background::JobRunner.start!
|
60
72
|
gadget, procon = ProconBypassMan::ConnectDeviceCommand.execute!
|
73
|
+
ProconBypassMan::DeviceStatus.change_to_running!
|
61
74
|
Runner.new(gadget: gadget, procon: procon).run
|
62
|
-
rescue CouldNotLoadConfigError
|
75
|
+
rescue ProconBypassMan::CouldNotLoadConfigError
|
63
76
|
ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。設定ファイルの読み込みに失敗しました")
|
77
|
+
ProconBypassMan::DeviceStatus.change_to_setting_syntax_error_and_shutdown!
|
78
|
+
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
79
|
+
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
80
|
+
exit 1
|
81
|
+
rescue ProconBypassMan::NotFoundProconError
|
82
|
+
ProconBypassMan::SendErrorCommand.execute(error: "プロコンが見つかりませんでした。終了します。")
|
83
|
+
ProconBypassMan::DeviceStatus.change_to_procon_not_found_error!
|
64
84
|
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
65
85
|
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
66
86
|
exit 1
|
67
|
-
rescue EternalConnectionError
|
87
|
+
rescue ProconBypassMan::EternalConnectionError
|
68
88
|
ProconBypassMan::SendErrorCommand.execute(error: "接続の見込みがないのでsleepしまくります")
|
89
|
+
ProconBypassMan::DeviceStatus.change_to_connected_but_sleeping!
|
69
90
|
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
70
|
-
|
71
|
-
rescue FirstConnectionError
|
91
|
+
eternal_sleep
|
92
|
+
rescue ProconBypassMan::FirstConnectionError
|
72
93
|
ProconBypassMan::SendErrorCommand.execute(error: "接続を確立できませんでした。やりなおします。")
|
73
94
|
retry
|
74
95
|
end
|
@@ -96,4 +117,8 @@ module ProconBypassMan
|
|
96
117
|
def self.initialize_pbm
|
97
118
|
ProconBypassMan::WriteDeviceIdCommand.execute
|
98
119
|
end
|
120
|
+
|
121
|
+
def self.eternal_sleep
|
122
|
+
sleep(999999999)
|
123
|
+
end
|
99
124
|
end
|
data/procon_bypass_man.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
# Uncomment to register a new dependency of your gem
|
31
|
-
|
31
|
+
spec.add_dependency "pbmenv"
|
32
32
|
|
33
33
|
# For more information and examples about making a new gem, checkout our
|
34
34
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/project_template/app.rb
CHANGED
data/sig/main.rbs
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: procon_bypass_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jiikko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pbmenv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: An extension for Nintendo Switch Pro Controller
|
14
28
|
email:
|
15
29
|
- n905i.1214@gmail.com
|
@@ -39,18 +53,20 @@ files:
|
|
39
53
|
- docs/setup_raspi_by_mitamae.md
|
40
54
|
- lib/procon_bypass_man.rb
|
41
55
|
- lib/procon_bypass_man/background.rb
|
42
|
-
- lib/procon_bypass_man/background/has_server_pool.rb
|
43
|
-
- lib/procon_bypass_man/background/http_client.rb
|
44
56
|
- lib/procon_bypass_man/background/job_performer.rb
|
45
|
-
- lib/procon_bypass_man/background/job_runnable.rb
|
46
57
|
- lib/procon_bypass_man/background/job_runner.rb
|
47
58
|
- lib/procon_bypass_man/background/jobs/base_job.rb
|
59
|
+
- lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb
|
60
|
+
- lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb
|
61
|
+
- lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb
|
62
|
+
- lib/procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job.rb
|
48
63
|
- lib/procon_bypass_man/background/jobs/report_boot_job.rb
|
49
64
|
- lib/procon_bypass_man/background/jobs/report_error_job.rb
|
50
|
-
- lib/procon_bypass_man/background/jobs/
|
65
|
+
- lib/procon_bypass_man/background/jobs/report_event_base_job.rb
|
51
66
|
- lib/procon_bypass_man/background/jobs/report_load_config_job.rb
|
52
67
|
- lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb
|
53
68
|
- lib/procon_bypass_man/background/jobs/report_reload_config_job.rb
|
69
|
+
- lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb
|
54
70
|
- lib/procon_bypass_man/boot_message.rb
|
55
71
|
- lib/procon_bypass_man/buttons_setting_configuration.rb
|
56
72
|
- lib/procon_bypass_man/buttons_setting_configuration/layer.rb
|
@@ -62,12 +78,15 @@ files:
|
|
62
78
|
- lib/procon_bypass_man/commands/bypass_command.rb
|
63
79
|
- lib/procon_bypass_man/commands/connect_device_command.rb
|
64
80
|
- lib/procon_bypass_man/commands/print_boot_message_command.rb
|
81
|
+
- lib/procon_bypass_man/commands/run_local_shell_command.rb
|
82
|
+
- lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb
|
65
83
|
- lib/procon_bypass_man/commands/send_error_command.rb
|
66
84
|
- lib/procon_bypass_man/commands/send_reload_config_event_command.rb
|
67
85
|
- lib/procon_bypass_man/commands/write_device_id_command.rb
|
68
86
|
- lib/procon_bypass_man/commands/write_session_id_command.rb
|
69
87
|
- lib/procon_bypass_man/configuration.rb
|
70
88
|
- lib/procon_bypass_man/device_connector.rb
|
89
|
+
- lib/procon_bypass_man/device_status.rb
|
71
90
|
- lib/procon_bypass_man/io_monitor.rb
|
72
91
|
- lib/procon_bypass_man/processor.rb
|
73
92
|
- lib/procon_bypass_man/procon.rb
|
@@ -82,7 +101,14 @@ files:
|
|
82
101
|
- lib/procon_bypass_man/procon/press_button_aware.rb
|
83
102
|
- lib/procon_bypass_man/procon/user_operation.rb
|
84
103
|
- lib/procon_bypass_man/procon_reader.rb
|
104
|
+
- lib/procon_bypass_man/remote_pbm_action.rb
|
105
|
+
- lib/procon_bypass_man/remote_pbm_action/base_action.rb
|
106
|
+
- lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb
|
107
|
+
- lib/procon_bypass_man/remote_pbm_action/lib/update_remote_pbm_action_status_command.rb
|
108
|
+
- lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb
|
109
|
+
- lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb
|
85
110
|
- lib/procon_bypass_man/runner.rb
|
111
|
+
- lib/procon_bypass_man/scheduler.rb
|
86
112
|
- lib/procon_bypass_man/splatoon2.rb
|
87
113
|
- lib/procon_bypass_man/splatoon2/macro/fast_return.rb
|
88
114
|
- lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb
|
@@ -92,10 +118,16 @@ files:
|
|
92
118
|
- lib/procon_bypass_man/splatoon2/version.rb
|
93
119
|
- lib/procon_bypass_man/support/callbacks.rb
|
94
120
|
- lib/procon_bypass_man/support/compress_array.rb
|
121
|
+
- lib/procon_bypass_man/support/http_client.rb
|
95
122
|
- lib/procon_bypass_man/support/on_memory_cache.rb
|
123
|
+
- lib/procon_bypass_man/support/report_http_client.rb
|
96
124
|
- lib/procon_bypass_man/support/safe_timeout.rb
|
125
|
+
- lib/procon_bypass_man/support/send_device_stats_http_client.rb
|
126
|
+
- lib/procon_bypass_man/support/server_pool.rb
|
97
127
|
- lib/procon_bypass_man/support/signal_handler.rb
|
128
|
+
- lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb
|
98
129
|
- lib/procon_bypass_man/support/uptime.rb
|
130
|
+
- lib/procon_bypass_man/value_objects/remote_pbm_action_object.rb
|
99
131
|
- lib/procon_bypass_man/version.rb
|
100
132
|
- procon_bypass_man.gemspec
|
101
133
|
- project_template/README.md
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module ProconBypassMan
|
2
|
-
module Background
|
3
|
-
class HttpClient
|
4
|
-
class HttpRequest
|
5
|
-
def self.request!(uri: , hostname: , params: , device_id: , session_id: nil, event_type: )
|
6
|
-
@uri = uri
|
7
|
-
@http = Net::HTTP.new(uri.host, uri.port)
|
8
|
-
@http.use_ssl = uri.scheme === "https"
|
9
|
-
@params = {
|
10
|
-
hostname: hostname,
|
11
|
-
event_type: event_type,
|
12
|
-
session_id: session_id,
|
13
|
-
device_id: device_id,
|
14
|
-
}.merge(params)
|
15
|
-
@http.post(
|
16
|
-
@uri.path,
|
17
|
-
@params.to_json,
|
18
|
-
{ "Content-Type" => "application/json" },
|
19
|
-
)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def initialize(path: , pool_server: , retry_on_connection_error: false)
|
24
|
-
@path = path
|
25
|
-
@pool_server = pool_server
|
26
|
-
@hostname = `hostname`.chomp
|
27
|
-
@retry_on_connection_error = retry_on_connection_error
|
28
|
-
end
|
29
|
-
|
30
|
-
def post(body: , event_type: )
|
31
|
-
if @pool_server.server.nil?
|
32
|
-
ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
|
33
|
-
return
|
34
|
-
end
|
35
|
-
|
36
|
-
params = { body: body.to_json }
|
37
|
-
session_id = ProconBypassMan.session_id
|
38
|
-
device_id = ProconBypassMan.device_id
|
39
|
-
|
40
|
-
response = HttpRequest.request!(
|
41
|
-
uri: URI.parse("#{@pool_server.server}#{@path}"),
|
42
|
-
hostname: @hostname,
|
43
|
-
device_id: device_id,
|
44
|
-
session_id: session_id,
|
45
|
-
params: params,
|
46
|
-
event_type: event_type,
|
47
|
-
)
|
48
|
-
case response.code
|
49
|
-
when /^200/
|
50
|
-
return
|
51
|
-
else
|
52
|
-
@pool_server.next!
|
53
|
-
ProconBypassMan.logger.error("200以外(#{response.code})が帰ってきました. #{response.body}")
|
54
|
-
end
|
55
|
-
rescue SocketError => e
|
56
|
-
ProconBypassMan.logger.error("error in outbound module: #{e}")
|
57
|
-
if @retry_on_connection_error
|
58
|
-
sleep(10)
|
59
|
-
retry
|
60
|
-
end
|
61
|
-
rescue => e
|
62
|
-
puts e
|
63
|
-
ProconBypassMan.logger.error("error in outbound module: #{e}")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
class ProconBypassMan::ReportHeartbeatJob < ProconBypassMan::BaseJob
|
2
|
-
# @param [String] body
|
3
|
-
def self.perform(body)
|
4
|
-
ProconBypassMan::Background::HttpClient.new(
|
5
|
-
path: path,
|
6
|
-
pool_server: pool_server,
|
7
|
-
retry_on_connection_error: false,
|
8
|
-
).post(body: body, event_type: :heartbeat)
|
9
|
-
end
|
10
|
-
end
|