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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +19 -6
  3. data/.github/workflows/gitleacks.yml +2 -1
  4. data/.github/workflows/release.yml +1 -0
  5. data/.github/workflows/ruby.yml +1 -1
  6. data/.rubocop.yml +4 -0
  7. data/.ruby-version +1 -1
  8. data/CHANGELOG.md +16 -1
  9. data/Gemfile +6 -3
  10. data/Gemfile.lock +3 -3
  11. data/README.md +17 -8
  12. data/Steepfile +0 -1
  13. data/bin/generate_default_app +10 -0
  14. data/docs/getting_started.md +98 -25
  15. data/docs/setup_raspi_by_mitamae.md +44 -2
  16. data/lib/procon_bypass_man/background/job_performer.rb +1 -2
  17. data/lib/procon_bypass_man/background/job_queue.rb +50 -0
  18. data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -1
  19. data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +2 -2
  20. data/lib/procon_bypass_man/background/jobs/concerns/job_performable.rb +16 -0
  21. data/lib/procon_bypass_man/background/jobs/post_completed_remote_macro_job.rb +1 -1
  22. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +1 -1
  23. data/lib/procon_bypass_man/background/jobs/report_completed_upgrade_pbm_job.rb +1 -1
  24. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +1 -1
  25. data/lib/procon_bypass_man/background/jobs/report_error_reload_config_job.rb +1 -1
  26. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +1 -1
  27. data/lib/procon_bypass_man/background/jobs/report_procon_performance_measurements_job.rb +43 -0
  28. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +1 -1
  29. data/lib/procon_bypass_man/background/jobs/report_start_reboot_job.rb +1 -1
  30. data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +1 -1
  31. data/lib/procon_bypass_man/background.rb +3 -4
  32. data/lib/procon_bypass_man/bypass/bypass_command.rb +6 -15
  33. data/lib/procon_bypass_man/bypass/bypass_value.rb +6 -0
  34. data/lib/procon_bypass_man/bypass/procon_to_switch.rb +107 -0
  35. data/lib/procon_bypass_man/bypass/switch_to_procon.rb +64 -0
  36. data/lib/procon_bypass_man/bypass.rb +5 -112
  37. data/lib/procon_bypass_man/configuration.rb +16 -40
  38. data/lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb +1 -1
  39. data/lib/procon_bypass_man/device_connection/procon_setting_overrider.rb +12 -3
  40. data/lib/procon_bypass_man/procon/macro.rb +1 -1
  41. data/lib/procon_bypass_man/procon/performance_measurement/last_bypass_at.rb +17 -0
  42. data/lib/procon_bypass_man/procon/performance_measurement/measurement_collection.rb +9 -0
  43. data/lib/procon_bypass_man/procon/performance_measurement/measurements_summarizer.rb +84 -0
  44. data/lib/procon_bypass_man/procon/performance_measurement/procon_performance_span_transfer_job.rb +8 -0
  45. data/lib/procon_bypass_man/procon/performance_measurement/queue_over_process.rb +38 -0
  46. data/lib/procon_bypass_man/procon/performance_measurement/span_queue.rb +42 -0
  47. data/lib/procon_bypass_man/procon/performance_measurement/span_transfer_buffer.rb +39 -0
  48. data/lib/procon_bypass_man/procon/performance_measurement.rb +103 -0
  49. data/lib/procon_bypass_man/procon.rb +2 -1
  50. data/lib/procon_bypass_man/procon_display/bypass_hook.rb +12 -0
  51. data/lib/procon_bypass_man/procon_display/http_request.rb +31 -0
  52. data/lib/procon_bypass_man/procon_display/http_response.rb +23 -0
  53. data/lib/procon_bypass_man/procon_display/server.rb +33 -0
  54. data/lib/procon_bypass_man/procon_display/server_app.rb +17 -0
  55. data/lib/procon_bypass_man/procon_display/status.rb +20 -0
  56. data/lib/procon_bypass_man/procon_display.rb +11 -0
  57. data/lib/procon_bypass_man/remote_macro/queue_over_process.rb +26 -44
  58. data/lib/procon_bypass_man/remote_macro/remote_macro_object.rb +22 -24
  59. data/lib/procon_bypass_man/remote_macro/remote_macro_receiver.rb +1 -1
  60. data/lib/procon_bypass_man/remote_macro/remote_macro_sender.rb +1 -1
  61. data/lib/procon_bypass_man/remote_macro/task.rb +1 -5
  62. data/lib/procon_bypass_man/remote_macro/task_queue.rb +6 -10
  63. data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb +1 -1
  64. data/lib/procon_bypass_man/runner.rb +4 -9
  65. data/lib/procon_bypass_man/scheduler.rb +15 -6
  66. data/lib/procon_bypass_man/support/callbacks.rb +72 -34
  67. data/lib/procon_bypass_man/support/can_over_process.rb +60 -0
  68. data/lib/procon_bypass_man/support/gc.rb +8 -0
  69. data/lib/procon_bypass_man/support/http_client.rb +9 -6
  70. data/lib/procon_bypass_man/support/load_agv.rb +20 -0
  71. data/lib/procon_bypass_man/support/procon_performance_http_client.rb +7 -0
  72. data/lib/procon_bypass_man/support/retryable.rb +16 -0
  73. data/lib/procon_bypass_man/support/signal_handler.rb +1 -1
  74. data/lib/procon_bypass_man/version.rb +1 -1
  75. data/lib/procon_bypass_man/websocket/client.rb +2 -2
  76. data/lib/procon_bypass_man/worker.rb +32 -0
  77. data/lib/procon_bypass_man.rb +41 -10
  78. data/procon_bypass_man.gemspec +1 -1
  79. data/project_template/README.md +0 -5
  80. data/project_template/app.rb +21 -11
  81. data/project_template/app.rb.erb +62 -0
  82. data/project_template/lib/app_generator.rb +31 -0
  83. data/project_template/web.rb +1 -1
  84. data/sig/main.rbs +10 -52
  85. data/tmp/.keep +0 -0
  86. metadata +34 -10
  87. data/lib/procon_bypass_man/background/job_runner.rb +0 -45
  88. data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +0 -5
  89. data/lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb +0 -16
  90. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +0 -15
  91. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +0 -44
  92. data/lib/procon_bypass_man/io_monitor.rb +0 -108
  93. data/lib/procon_bypass_man/support/server_pool.rb +0 -46
@@ -1,15 +0,0 @@
1
- class ProconBypassMan::ReportPressedButtonsJob < ProconBypassMan::BaseJob
2
- extend ProconBypassMan::HasInternalApiSetting
3
-
4
- # @param [String] body
5
- def self.perform(body)
6
- ProconBypassMan::ReportHttpClient.new(
7
- path: path,
8
- server_pool: server_pool,
9
- ).post(body: body, event_type: :internal)
10
- end
11
-
12
- def self.path
13
- "/api/pressed_buttons"
14
- end
15
- end
@@ -1,44 +0,0 @@
1
- class ProconBypassMan::Bypass
2
- module UsbHidLogger
3
- extend ProconBypassMan::Callbacks::ClassMethods
4
- include ProconBypassMan::Callbacks
5
-
6
- define_callbacks :send_gadget_to_procon
7
- define_callbacks :send_procon_to_gadget
8
-
9
- set_callback :send_gadget_to_procon, :after, :log_send_gadget_to_procon
10
- set_callback :send_procon_to_gadget, :after, :log_procon_to_gadget
11
-
12
- def log_send_gadget_to_procon
13
- return unless bypass_value.to_text
14
-
15
- if ProconBypassMan.config.verbose_bypass_log
16
- ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
17
- else
18
- ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
19
- ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
20
- end
21
- end
22
- end
23
-
24
- def log_procon_to_gadget
25
- return unless bypass_value.to_text
26
-
27
- if ProconBypassMan.config.verbose_bypass_log
28
- ProconBypassMan.logger.debug { "<<< #{bypass_value.to_text}" }
29
- else
30
- ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
31
- ProconBypassMan.logger.debug { "<<< #{bypass_value.to_text}" }
32
- end
33
- end
34
-
35
- if ProconBypassMan.config.enable_reporting_pressed_buttons
36
- ProconBypassMan.cache.fetch key: 'pressed_buttons_reporter', expires_in: 5 do
37
- ProconBypassMan::ReportPressedButtonsJob.perform_async(
38
- bypass_value.binary.to_procon_reader.to_hash
39
- )
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,108 +0,0 @@
1
- module ProconBypassMan
2
- class NullCounter
3
- def initialize(label: )
4
- end
5
-
6
- def record(_)
7
- end
8
-
9
- def shutdown
10
- end
11
- end
12
-
13
- class Counter
14
- attr_accessor :label, :table, :previous_table, :active
15
-
16
- def initialize(label: )
17
- self.label = label
18
- self.table = {}
19
- self.previous_table = {}
20
- self.active = true
21
- end
22
-
23
- # アクティブなバケットは1つだけ
24
- def record(event_name)
25
- key = Time.now.strftime("%S").to_i
26
- if table[key].nil?
27
- self.previous_table = table.values.first
28
- self.table = {}
29
- table[key] = {}
30
- end
31
- if table[key][event_name].nil?
32
- table[key][event_name] = 1
33
- else
34
- table[key][event_name] += 1
35
- end
36
- self
37
- end
38
-
39
- def formatted_previous_table
40
- t = previous_table.dup
41
- start_function = t[:start_function] || 0
42
- end_function = t[:end_function] || 0
43
- eagain_wait_readable_on_read = t[:eagain_wait_readable_on_read] || 0
44
- eagain_wait_readable_on_write = t[:eagain_wait_readable_on_write] || 0
45
- "(#{(end_function / start_function.to_f * 100).floor(1)}%(#{end_function}/#{start_function}), loss: #{eagain_wait_readable_on_read}, #{eagain_wait_readable_on_write})"
46
- end
47
-
48
- def shutdown
49
- self.active = false
50
- end
51
- end
52
-
53
- module IOMonitor
54
- @@thread = nil
55
-
56
- def self.new(label: )
57
- return NullCounter.new(label: label) if not started?
58
-
59
- counter = Counter.new(label: label)
60
- @@list << counter
61
- counter
62
- end
63
-
64
- # @return [Array<Counter>]
65
- def self.targets
66
- @@list
67
- end
68
-
69
- def self.started?
70
- !!@@thread
71
- end
72
-
73
- # ここで集計する
74
- def self.start!
75
- @@thread = Thread.start do
76
- max_output_length = 0
77
- loop do
78
- list = @@list.select(&:active).dup
79
- unless list.all? { |x| x&.previous_table.is_a?(Hash) }
80
- sleep 0.5
81
- next
82
- end
83
-
84
- line = list.map { |counter|
85
- "#{counter.label}(#{counter.formatted_previous_table})"
86
- }.join(", ")
87
- max_output_length = line.length
88
- sleep 0.7
89
-
90
- if ENV["PBM_FOREGROUND"]
91
- print "\r"
92
- print " " * max_output_length
93
- print "\r"
94
- print line
95
- end
96
- ProconBypassMan.logger.debug { line }
97
- break if $will_terminate_token
98
- end
99
- end
100
- end
101
-
102
- def self.reset!
103
- @@list = []
104
- end
105
-
106
- reset!
107
- end
108
- end
@@ -1,46 +0,0 @@
1
- module ProconBypassMan
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
- private
33
-
34
- def reset
35
- @index = 0
36
- end
37
-
38
- def inc_index
39
- @index = @index + 1
40
- end
41
- end
42
- end
43
-
44
- if $0 == __FILE__
45
- ProconBypassMan::ServerPool.new(servers: ['http://example.com'])
46
- end