Class: WifiWand::StatusLineDataBuilder
- Inherits:
-
Object
- Object
- WifiWand::StatusLineDataBuilder
- Includes:
- Timing
- Defined in:
- lib/wifi_wand/services/status_line_data_builder.rb
Constant Summary collapse
- DEFAULT_NETWORK_WORKER_RESULT_TIMEOUT_SECONDS =
2- DEFAULT_CONNECTIVITY_WORKER_RESULT_TIMEOUT_SECONDS =
2- DEFAULT_WORKER_RESULT_POLL_INTERVAL_SECONDS =
0.01- DEFAULT_WORKER_CLEANUP_TIMEOUT_SECONDS =
0.05- WORKER_BOUNDARY_ERROR =
StandardError excludes process-control and VM-level exceptions like Interrupt, SystemExit, and NoMemoryError.
StandardError
Instance Attribute Summary collapse
-
#expected_network_errors ⇒ Object
readonly
Returns the value of attribute expected_network_errors.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
Instance Method Summary collapse
- #call(progress_callback: nil) ⇒ Object
- #err_stream ⇒ Object
-
#initialize(model, runtime_config: nil, expected_network_errors: [], network_worker_result_timeout_seconds: nil, connectivity_worker_result_timeout_seconds: nil, worker_result_poll_interval_seconds: DEFAULT_WORKER_RESULT_POLL_INTERVAL_SECONDS, worker_cleanup_timeout_seconds: DEFAULT_WORKER_CLEANUP_TIMEOUT_SECONDS, **kwargs) ⇒ StatusLineDataBuilder
constructor
A new instance of StatusLineDataBuilder.
- #out_stream ⇒ Object
- #verbose? ⇒ Boolean
Methods included from Timing
monotonic_now, status_deadline, status_timeout_for
Constructor Details
#initialize(model, runtime_config: nil, expected_network_errors: [], network_worker_result_timeout_seconds: nil, connectivity_worker_result_timeout_seconds: nil, worker_result_poll_interval_seconds: DEFAULT_WORKER_RESULT_POLL_INTERVAL_SECONDS, worker_cleanup_timeout_seconds: DEFAULT_WORKER_CLEANUP_TIMEOUT_SECONDS, **kwargs) ⇒ StatusLineDataBuilder
Returns a new instance of StatusLineDataBuilder.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wifi_wand/services/status_line_data_builder.rb', line 25 def initialize( model, runtime_config: nil, expected_network_errors: [], network_worker_result_timeout_seconds: nil, connectivity_worker_result_timeout_seconds: nil, worker_result_poll_interval_seconds: DEFAULT_WORKER_RESULT_POLL_INTERVAL_SECONDS, worker_cleanup_timeout_seconds: DEFAULT_WORKER_CLEANUP_TIMEOUT_SECONDS, **kwargs ) @model = model @runtime_config = runtime_config || RuntimeConfig.new( verbose: kwargs[:verbose], out_stream: kwargs.key?(:out_stream) ? kwargs[:out_stream] : $stdout ) @expected_network_errors = expected_network_errors @network_worker_result_timeout_seconds = network_worker_result_timeout_seconds || DEFAULT_NETWORK_WORKER_RESULT_TIMEOUT_SECONDS @connectivity_worker_result_timeout_seconds = connectivity_worker_result_timeout_seconds || DEFAULT_CONNECTIVITY_WORKER_RESULT_TIMEOUT_SECONDS @worker_result_poll_interval_seconds = worker_result_poll_interval_seconds @worker_cleanup_timeout_seconds = worker_cleanup_timeout_seconds @cancellation_mutex = Mutex.new reset_worker_cancellation! @worker_registry_mutex = Mutex.new @worker_deadlines = {} @straggler_threads = [] end |
Instance Attribute Details
#expected_network_errors ⇒ Object (readonly)
Returns the value of attribute expected_network_errors.
18 19 20 |
# File 'lib/wifi_wand/services/status_line_data_builder.rb', line 18 def expected_network_errors @expected_network_errors end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
18 19 20 |
# File 'lib/wifi_wand/services/status_line_data_builder.rb', line 18 def model @model end |
Class Method Details
.call(model, progress_callback: nil) ⇒ Object
21 22 23 |
# File 'lib/wifi_wand/services/status_line_data_builder.rb', line 21 def self.call(model, progress_callback: nil, **) new(model, **).call(progress_callback: progress_callback) end |
Instance Method Details
#call(progress_callback: nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/wifi_wand/services/status_line_data_builder.rb', line 58 def call(progress_callback: nil) reset_worker_cancellation! reap_straggler_threads worker_start_time = monotonic_now partial = initial_data(worker_start_time) progress_callback&.call(partial.dup) unless partial[:wifi_on] partial.merge!(data_when_wifi_off) progress_callback&.call(partial.dup) return partial end result_queue = Queue.new network_thread, connectivity_thread = build_status_threads(result_queue, worker_start_time) cached_results = {} partial.merge!(await_worker_result(result_queue, :network, cached_results, worker_start_time)) progress_callback&.call(partial.dup) partial.merge!(await_worker_result(result_queue, :connectivity, cached_results, worker_start_time)) final_data = partial.dup progress_callback&.call(final_data) final_data rescue WifiWand::CommandNotFoundError, WifiWand::MethodNotImplementedError raise rescue *expected_network_errors, WifiWand::Error => e err_stream.puts "Warning: status_line_data failed: #{e.class}: #{e.}" if verbose? progress_callback&.call(nil) nil ensure cleanup_worker_threads(network_thread, connectivity_thread) end |
#err_stream ⇒ Object
56 |
# File 'lib/wifi_wand/services/status_line_data_builder.rb', line 56 def err_stream = runtime_config.err_stream |
#out_stream ⇒ Object
54 |
# File 'lib/wifi_wand/services/status_line_data_builder.rb', line 54 def out_stream = runtime_config.out_stream |
#verbose? ⇒ Boolean
288 |
# File 'lib/wifi_wand/services/status_line_data_builder.rb', line 288 def verbose? = runtime_config.verbose |