procon_bypass_man 0.1.9 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rubocop.yml +2 -0
  4. data/CHANGELOG.md +14 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +13 -12
  7. data/README.md +14 -16
  8. data/bin/console +4 -0
  9. data/bin/{report_receive_server.rb → dev_api_server.rb} +8 -1
  10. data/lib/procon_bypass_man/background/has_server_pool.rb +54 -0
  11. data/lib/procon_bypass_man/background/http_client.rb +67 -0
  12. data/lib/procon_bypass_man/background/job_performer.rb +16 -0
  13. data/lib/procon_bypass_man/background/job_runnable.rb +16 -0
  14. data/lib/procon_bypass_man/background/job_runner.rb +45 -0
  15. data/lib/procon_bypass_man/background/jobs/base_job.rb +12 -0
  16. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +10 -0
  17. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +10 -0
  18. data/lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb +10 -0
  19. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +10 -0
  20. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +18 -0
  21. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +10 -0
  22. data/lib/procon_bypass_man/background.rb +12 -0
  23. data/lib/procon_bypass_man/boot_message.rb +13 -9
  24. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/layer.rb +51 -30
  25. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/loader.rb +12 -11
  26. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/validator.rb +1 -1
  27. data/lib/procon_bypass_man/buttons_setting_configuration.rb +101 -0
  28. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +42 -0
  29. data/lib/procon_bypass_man/bypass.rb +57 -38
  30. data/lib/procon_bypass_man/commands/bypass_command.rb +86 -0
  31. data/lib/procon_bypass_man/commands/connect_device_command.rb +11 -0
  32. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +9 -0
  33. data/lib/procon_bypass_man/commands/send_error_command.rb +19 -0
  34. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +11 -0
  35. data/lib/procon_bypass_man/commands/write_device_id_command.rb +12 -0
  36. data/lib/procon_bypass_man/commands/write_session_id_command.rb +13 -0
  37. data/lib/procon_bypass_man/commands.rb +7 -0
  38. data/lib/procon_bypass_man/configuration.rb +92 -78
  39. data/lib/procon_bypass_man/device_connector.rb +31 -25
  40. data/lib/procon_bypass_man/io_monitor.rb +9 -4
  41. data/lib/procon_bypass_man/procon/analog_stick.rb +31 -0
  42. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +9 -32
  43. data/lib/procon_bypass_man/procon/button_collection.rb +1 -0
  44. data/lib/procon_bypass_man/procon/{data.rb → consts.rb} +1 -1
  45. data/lib/procon_bypass_man/procon/layer_changer.rb +40 -0
  46. data/lib/procon_bypass_man/procon/macro_registry.rb +2 -2
  47. data/lib/procon_bypass_man/procon/mode_registry.rb +2 -2
  48. data/lib/procon_bypass_man/procon/user_operation.rb +15 -17
  49. data/lib/procon_bypass_man/procon.rb +15 -15
  50. data/lib/procon_bypass_man/procon_reader.rb +31 -0
  51. data/lib/procon_bypass_man/runner.rb +15 -113
  52. data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +15 -0
  53. data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +15 -0
  54. data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +15 -0
  55. data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +15 -0
  56. data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +57 -0
  57. data/lib/procon_bypass_man/splatoon2/version.rb +7 -0
  58. data/lib/procon_bypass_man/splatoon2.rb +11 -0
  59. data/lib/procon_bypass_man/support/callbacks.rb +70 -0
  60. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  61. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  62. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  63. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  64. data/lib/procon_bypass_man/support/uptime.rb +25 -0
  65. data/lib/procon_bypass_man/version.rb +1 -1
  66. data/lib/procon_bypass_man.rb +41 -82
  67. data/procon_bypass_man.gemspec +2 -2
  68. data/project_template/README.md +19 -12
  69. data/project_template/app.rb +7 -8
  70. data/project_template/systemd_units/pbm_web.service +11 -0
  71. data/project_template/web.rb +16 -0
  72. data/sig/{README.rb → README.md} +0 -0
  73. data/sig/main.rbs +54 -16
  74. metadata +53 -22
  75. data/examples/practical/app.rb +0 -21
  76. data/examples/practical/setting.yml +0 -24
  77. data/lib/procon_bypass_man/analog_stick_position.rb +0 -14
  78. data/lib/procon_bypass_man/error_reporter.rb +0 -44
  79. data/lib/procon_bypass_man/procon/debug_dumper.rb +0 -17
  80. data/lib/procon_bypass_man/procon/layer_changeable.rb +0 -28
  81. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +0 -15
  82. data/lib/procon_bypass_man/reporter.rb +0 -42
  83. data/lib/procon_bypass_man/uptime.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e4ad788ed57ca3bac1d4d17b1648285c8bc8d89d23a3c0a4ca4d5aaa58e4dfd
4
- data.tar.gz: 512a1f754cf255c6692ab597c7997d6bad3f3004c2f1203a1ce6adaec603e655
3
+ metadata.gz: 62fab79bffee3adf43af06325d7ef6bce2060f844d8caaa824968ff77219e5de
4
+ data.tar.gz: c15ab8b50da926169727b9af5ff097585cd35c7e24fdf2ce75d2ca7d4fe5f07e
5
5
  SHA512:
6
- metadata.gz: 7a059a91051aee0fa59beb62aa7bd952b1c8db15a75d66c47a66fdbda96a60cd9285094524e1d3c619ec215fa47dc5f9ee44e4dd7524f6c2bd60a4d0dfcf25e3
7
- data.tar.gz: 9748ad5293f1e3cc902d9b74bbb40997d0c9588e43e78ab4299eb4ddbb9bfd030a7f3bf717d58a3207ac51e348cc090b1a726d7f63780d705807e04db7d9201d
6
+ metadata.gz: c94bc5e37b89c54a31fe165e53f84ac32c1b4d10fc617cc1397e0347baf1a39206fd50aff3a65626b8546545d00f33ac0e44a90da5ff25c02778d27e60aafe0f
7
+ data.tar.gz: 7ad56ef9e17bb8a26d840003faf8fa7d065ba878182dcd23d66118b43053c2827221814f37bb4098174cdfbcc449486d895bf6431520f60ce295a4e7382c39e7
data/.gitignore CHANGED
@@ -8,3 +8,8 @@
8
8
  /tmp/
9
9
  vendor
10
10
  todo.local.md
11
+ *.log
12
+ .setting_yaml_digest
13
+ pbm_pid
14
+ setting.yml
15
+ device_id
data/.rubocop.yml CHANGED
@@ -22,3 +22,5 @@ Lint/UselessAssignment:
22
22
  Enabled: false
23
23
  Lint/EmptyBlock:
24
24
  Enabled: false
25
+ Lint/ReturnInVoidContext:
26
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [0.1.13] - 2021-11-24
2
+ - 起動を早くするために、procon_bypass_man-splatoon2を同梱しました
3
+
4
+ ## [0.1.12] - 2021-11-18
5
+ - 起動ログなどを設定した外部サーバに送信できるようにしました
6
+
7
+ ## [0.1.11] - 2021-11-05
8
+ - PBM-WEB(>= 0.1.3)でボタンの入力を見るためのスレッドが動くようになりました
9
+
10
+ ## [0.1.10] - 2021-10-28
11
+ - ボタンを無効化するdisableを設定できるようになりました
12
+ - pvmenvで生成する初期ファイルにprocon_bypass_man-webを同梱しました
13
+ - PBM自体の設定の構文を変更しました
14
+
1
15
  ## [0.1.9] - 2021-10-20
2
16
  - 左スティックを傾けた時に設定した最大値内に丸めることができるようになりました
3
17
  - 関連メソッド: set_neutral_position, left_analog_stick_cap
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in procon_bypass_man.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "rake"
9
9
  gem "rspec"
10
10
  gem "pry"
11
11
  gem "timecop"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.9)
4
+ procon_bypass_man (0.1.13)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,7 +17,7 @@ GEM
17
17
  concurrent-ruby (1.1.9)
18
18
  diff-lcs (1.4.4)
19
19
  ffi (1.15.4)
20
- i18n (1.8.10)
20
+ i18n (1.8.11)
21
21
  concurrent-ruby (~> 1.0)
22
22
  language_server-protocol (3.16.0.3)
23
23
  listen (3.7.0)
@@ -27,7 +27,7 @@ GEM
27
27
  minitest (5.14.4)
28
28
  mustermann (1.1.1)
29
29
  ruby2_keywords (~> 0.0.1)
30
- parallel (1.20.1)
30
+ parallel (1.21.0)
31
31
  parser (3.0.2.0)
32
32
  ast (~> 2.4.1)
33
33
  pry (0.14.1)
@@ -41,7 +41,7 @@ GEM
41
41
  rb-fsevent (0.11.0)
42
42
  rb-inotify (0.10.1)
43
43
  ffi (~> 1.0)
44
- rbs (1.6.2)
44
+ rbs (1.7.1)
45
45
  regexp_parser (2.1.1)
46
46
  rexml (3.2.5)
47
47
  rspec (3.10.0)
@@ -56,17 +56,17 @@ GEM
56
56
  rspec-mocks (3.10.2)
57
57
  diff-lcs (>= 1.2.0, < 2.0)
58
58
  rspec-support (~> 3.10.0)
59
- rspec-support (3.10.2)
60
- rubocop (1.20.0)
59
+ rspec-support (3.10.3)
60
+ rubocop (1.23.0)
61
61
  parallel (~> 1.10)
62
62
  parser (>= 3.0.0.0)
63
63
  rainbow (>= 2.2.2, < 4.0)
64
64
  regexp_parser (>= 1.8, < 3.0)
65
65
  rexml
66
- rubocop-ast (>= 1.9.1, < 2.0)
66
+ rubocop-ast (>= 1.12.0, < 2.0)
67
67
  ruby-progressbar (~> 1.7)
68
68
  unicode-display_width (>= 1.4.0, < 3.0)
69
- rubocop-ast (1.11.0)
69
+ rubocop-ast (1.13.0)
70
70
  parser (>= 3.0.1.1)
71
71
  ruby-progressbar (1.11.0)
72
72
  ruby2_keywords (0.0.5)
@@ -90,20 +90,21 @@ GEM
90
90
  timecop (0.9.4)
91
91
  tzinfo (2.0.4)
92
92
  concurrent-ruby (~> 1.0)
93
- unicode-display_width (2.0.0)
93
+ unicode-display_width (2.1.0)
94
94
  webrick (1.7.0)
95
- zeitwerk (2.4.2)
95
+ zeitwerk (2.5.1)
96
96
 
97
97
  PLATFORMS
98
98
  arm-linux
99
99
  arm64-darwin-20
100
+ arm64-darwin-21
100
101
  armv7l-linux
101
102
  x86_64-linux
102
103
 
103
104
  DEPENDENCIES
104
105
  procon_bypass_man!
105
106
  pry
106
- rake (~> 13.0)
107
+ rake
107
108
  rbs
108
109
  rspec
109
110
  rubocop
@@ -113,4 +114,4 @@ DEPENDENCIES
113
114
  webrick
114
115
 
115
116
  BUNDLED WITH
116
- 2.2.22
117
+ 2.2.30
data/README.md CHANGED
@@ -28,8 +28,8 @@ Switch <-- (PBM): ZR連打
28
28
  ## Usage
29
29
  * USBガジェットモードで起動するRaspberry Pi4を用意する
30
30
  * https://github.com/splaplapla/procon_bypass_man/blob/master/docs/setup_raspi.md
31
- * Raspberry Pi4で https://github.com/jiikko/procon_bypass_man_sample をclone して実行ファイルを動かす
32
- * 実行ファイルと設定ファイルについては https://github.com/splaplapla/procon_bypass_man/wiki に詳細を書いていますが、まず動かすためにはcloneしたほうが早いです
31
+ * Raspberry Pi4 sudo pbmenv install latest && cd /usr/share/pbm/current && sudo ruby app.rb
32
+ * 動いたのを確認したらserviceとして登録にするなどしてください
33
33
 
34
34
  ## Plugins
35
35
  * https://github.com/splaplapla/procon_bypass_man-splatoon2
@@ -52,6 +52,8 @@ Switch <-- (PBM): ZR連打
52
52
  * 連射中には特定のキーの入力を無視したり、複数のキーをトリガーに連射することができます
53
53
  * どうしてsudoが必要なの?
54
54
  * 操作するdeviceファイルの所有者がrootだから
55
+ * 市販されているサードパーティ製連射機との違いは?
56
+ * サードパーティ製のコントローラーは、設定方法や形状が特殊で買い換えるたびに学習・設定コストが発生します。本ツールを使えば、設定内容はテキストで管理することができ、使い慣れたプロコンで同等のことができます。
55
57
 
56
58
  ## TODO
57
59
  * レコーディング機能(プロコンの入力をマクロとして登録ができる)
@@ -59,32 +61,28 @@ Switch <-- (PBM): ZR連打
59
61
  * 設定ファイル マクロの引数に、ボタンを取れるようにする
60
62
 
61
63
  ## 開発系
62
- ```ruby
63
- ProconBypassMan.tap do |pbm|
64
- pbm.root = File.expand_path(__dir__)
65
- pbm.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
66
- pbm.logger.level = :debug
67
- end
68
- ```
69
-
70
64
  ### プロコンとの接続を維持したまま、現在の設定ファイルをPBMに反映する
71
65
  ```shell
72
66
  sudo kill -USR2 `cat ./pbm_pid`
73
67
  ```
74
68
 
75
69
  ### 起動ログをサーバに送信する
76
- * `ProconBypassMan.api_server = "http://.."` を設定すると、 `POST /api/reports` に対して起動ログを送信するようになります
70
+ * `ProconBypassMan.api_server = "http://.."` を設定すると、 `POST /api/events` に対して起動ログなどを送信するようになります
77
71
 
78
72
  ### 開発環境でログの送信を確認する方法
79
- * `bundle exec bin/report_receive_server.rb`
80
- * `bin/console`
81
- * `ProconBypassMan.api_server = "http://localhost:4567"`
82
- * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::Reporter.report(body: message.to_hash)"`
73
+ * `bundle exec bin/dev_api_server.rb`
74
+ * `API_SERVER=http://localhost:4567 INTERNAL_API_SERVER=http://localhost:4567 bin/console`
75
+ * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::ReportBootJob.perform(body: message.to_hash)`
83
76
 
84
77
  ### リリース手順
85
- * project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
78
+ * project_template/web.rb, project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
79
+ * CHANGELOG.md に日付を書く
86
80
  * be rake release
87
81
 
88
82
  ## License
89
83
 
90
84
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
85
+
86
+
87
+ ## Links
88
+ * https://discord.gg/bEcRNKf4ep
data/bin/console CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  require "bundler/setup"
5
5
  require "procon_bypass_man"
6
+ require "pry"
6
7
 
7
8
  # You can add fixtures and/or initialization code here to make experimenting
8
9
  # with your gem easier. You can also use a different console, if you like.
@@ -12,4 +13,7 @@ require "procon_bypass_man"
12
13
  # Pry.start
13
14
 
14
15
  require "irb"
16
+
17
+ ProconBypassMan.config.logger = Logger.new($stdout)
18
+
15
19
  IRB.start(__FILE__)
@@ -4,8 +4,15 @@ require "sinatra"
4
4
  require "webrick"
5
5
  require "pry"
6
6
 
7
- post '/api/reports' do
7
+ post '/api/events' do
8
8
  puts JSON.parse(request.body.read)
9
9
  status 200
10
10
  body ''
11
11
  end
12
+
13
+ post '/api/pressed_buttons' do
14
+ r = JSON.parse(request.body.read)
15
+ puts r
16
+ status 200
17
+ body ''
18
+ end
@@ -0,0 +1,54 @@
1
+ module ProconBypassMan::Background::HasServerPool
2
+ class ServerPool
3
+ def initialize(servers: )
4
+ if servers.nil? || servers.empty?
5
+ return
6
+ end
7
+
8
+ @servers = servers
9
+ if @servers.size >= 1
10
+ @index = 0
11
+ else
12
+ @index = nil
13
+ end
14
+ end
15
+
16
+ def pick
17
+ if @index.nil?
18
+ return @servers&.first
19
+ end
20
+ @servers[@index] or raise "bug!!!"
21
+ end
22
+ def server; pick; end
23
+
24
+ def next!
25
+ inc_index
26
+ if @servers[@index].nil?
27
+ reset
28
+ return
29
+ end
30
+ end
31
+
32
+ def reset
33
+ @index = 0
34
+ end
35
+
36
+ def inc_index
37
+ @index = @index + 1
38
+ end
39
+ 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
+ end
@@ -0,0 +1,67 @@
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
@@ -0,0 +1,16 @@
1
+ module ProconBypassMan
2
+ module Background
3
+ class JobPerformer
4
+ def initialize(klass: , args: )
5
+ @klass = klass
6
+ @args = args
7
+ end
8
+
9
+ def perform
10
+ @klass.perform(*@args)
11
+ rescue => e
12
+ ProconBypassMan::ReportErrorJob.perform(e)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module ProconBypassMan
2
+ module Background
3
+ module JobRunnable
4
+ def perform(*)
5
+ raise NotImplementedError, nil
6
+ end
7
+
8
+ def perform_async(*args)
9
+ ProconBypassMan::Background::JobRunner.push(
10
+ args: args,
11
+ reporter_class: self,
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,45 @@
1
+ module ProconBypassMan
2
+ module Background
3
+ class JobRunner
4
+ MAX_QUEUE_SIZE = 100
5
+
6
+ def self.start!
7
+ new.start!
8
+ end
9
+
10
+ # for test
11
+ def stop!
12
+ return unless defined?(@thread)
13
+ @thread.kill
14
+ end
15
+
16
+ def start!
17
+ return if defined?(@thread)
18
+ @thread = Thread.new do
19
+ while(item = self.class.queue.pop)
20
+ begin
21
+ JobPerformer.new(klass: item[:reporter_class], args: item[:args]).perform
22
+ sleep(1)
23
+ rescue => e
24
+ ProconBypassMan.logger.error(e)
25
+ end
26
+ end
27
+ end
28
+ self
29
+ end
30
+
31
+ def self.queue
32
+ @@queue ||= Queue.new
33
+ end
34
+
35
+ def self.push(hash)
36
+ if queue.size > MAX_QUEUE_SIZE
37
+ ProconBypassMan.logger.error('Over queue size cap!!')
38
+ return
39
+ end
40
+
41
+ queue.push(hash)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ class ProconBypassMan::BaseJob
2
+ extend ProconBypassMan::Background::HasServerPool
3
+ extend ProconBypassMan::Background::JobRunnable
4
+
5
+ def self.servers
6
+ ProconBypassMan.config.api_servers
7
+ end
8
+
9
+ def self.path
10
+ "/api/events"
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class ProconBypassMan::ReportBootJob < 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: true,
8
+ ).post(body: body, event_type: :boot)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class ProconBypassMan::ReportErrorJob < 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: :error,)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,10 @@
1
+ class ProconBypassMan::ReportLoadConfigJob < 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: :load_config)
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ class ProconBypassMan::ReportPressedButtonsJob
2
+ extend ProconBypassMan::Background::HasServerPool
3
+ extend ProconBypassMan::Background::JobRunnable
4
+
5
+ PATH = "/api/pressed_buttons"
6
+
7
+ # @param [String] body
8
+ def self.perform(body)
9
+ ProconBypassMan::Background::HttpClient.new(
10
+ path: PATH,
11
+ pool_server: pool_server,
12
+ ).post(body: body, event_type: :internal)
13
+ end
14
+
15
+ def self.servers
16
+ ProconBypassMan.config.internal_api_servers
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ class ProconBypassMan::ReportReloadConfigJob < 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: :reload_config)
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require "procon_bypass_man/background/job_runnable"
2
+ require "procon_bypass_man/background/job_runner"
3
+ 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
+ require "procon_bypass_man/background/jobs/base_job"
7
+ require "procon_bypass_man/background/jobs/report_boot_job"
8
+ require "procon_bypass_man/background/jobs/report_reload_config_job"
9
+ require "procon_bypass_man/background/jobs/report_load_config_job"
10
+ require "procon_bypass_man/background/jobs/report_error_job"
11
+ require "procon_bypass_man/background/jobs/report_heartbeat_job"
12
+ require "procon_bypass_man/background/jobs/report_pressed_buttons_job"
@@ -6,15 +6,19 @@ class ProconBypassMan::BootMessage
6
6
  @table[:pid] = $$
7
7
  @table[:root_path] = ProconBypassMan.root
8
8
  @table[:pid_path] = ProconBypassMan.pid_path
9
- @table[:setting_path] = ProconBypassMan::Configuration.instance.setting_path
9
+ @table[:setting_path] = ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path
10
10
  @table[:uptime_from_boot] = ProconBypassMan::Uptime.from_boot
11
+ @table[:use_pbmenv] = !(!!`which pbmenv`.empty?)
11
12
 
12
- build_version = `git rev-parse --short HEAD`.chomp
13
- if build_version.empty?
14
- @table[:build_version] = 'release version'
15
- else
16
- @table[:build_version] = build_version
17
- end
13
+ # 開発中のHEADを取りたかったけど、Gem::Specification経由から取得する必要がありそう
14
+ # build_version = `git rev-parse --short HEAD`.chomp
15
+ # if build_version.empty?
16
+ # @table[:build_version] = 'release version'
17
+ # else
18
+ # @table[:build_version] = build_version
19
+ # end
20
+
21
+ # build version: #{@table[:build_version]}
18
22
  end
19
23
 
20
24
  # @return [String]
@@ -22,13 +26,13 @@ class ProconBypassMan::BootMessage
22
26
  booted_message = <<~EOF
23
27
  ----
24
28
  RUBY_VERSION: #{@table[:ruby_version]}
25
- ProconBypassMan: #{@table[:pbm_version]}
29
+ ProconBypassMan::VERSION: #{@table[:pbm_version]}
26
30
  pid: #{@table[:pid]}
27
31
  root: #{@table[:root_path]}
28
32
  pid_path: #{@table[:pid_path]}
29
33
  setting_path: #{@table[:setting_path]}
30
34
  uptime from boot: #{@table[:uptime_from_boot]} sec
31
- build version: #{@table[:build_version]}
35
+ use_pbmenv: #{@table[:use_pbmenv]}
32
36
  ----
33
37
  EOF
34
38
  end