Class: PatientHttp::Sidekiq::ProcessorObserver
- Inherits:
-
ProcessorObserver
- Object
- ProcessorObserver
- PatientHttp::Sidekiq::ProcessorObserver
- Defined in:
- lib/patient_http/sidekiq/processor_observer.rb
Overview
Procesor Observer that collect stats in Redis for the WebUI and monitors for crashed processes in order to re-enqueue workers.
Instance Attribute Summary collapse
-
#task_monitor ⇒ Object
readonly
Returns the value of attribute task_monitor.
Instance Method Summary collapse
- #capacity_exceeded ⇒ Object
-
#initialize(processor) ⇒ ProcessorObserver
constructor
A new instance of ProcessorObserver.
- #request_end(request_task) ⇒ Object
- #request_error(error) ⇒ Object
- #request_start(request_task) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(processor) ⇒ ProcessorObserver
Returns a new instance of ProcessorObserver.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 10 def initialize(processor) @processor = processor @stats = Stats.new(processor.config) @task_monitor = TaskMonitor.new(processor.config) @monitor_thread = TaskMonitorThread.new( processor.config, @task_monitor, -> { @processor.inflight_request_ids } ) end |
Instance Attribute Details
#task_monitor ⇒ Object (readonly)
Returns the value of attribute task_monitor.
8 9 10 |
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 8 def task_monitor @task_monitor end |
Instance Method Details
#capacity_exceeded ⇒ Object
30 31 32 |
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 30 def capacity_exceeded @stats.record_capacity_exceeded end |
#request_end(request_task) ⇒ Object
38 39 40 41 |
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 38 def request_end(request_task) task_monitor.unregister(request_task) @stats.record_request(request_task.response&.status, request_task.duration) end |
#request_error(error) ⇒ Object
43 44 45 46 |
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 43 def request_error(error) error_type = error.is_a?(PatientHttp::Error) ? error.error_type : :exception @stats.record_error(error_type) end |
#request_start(request_task) ⇒ Object
34 35 36 |
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 34 def request_start(request_task) task_monitor.register(request_task) end |
#start ⇒ Object
21 22 23 |
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 21 def start @monitor_thread.start end |
#stop ⇒ Object
25 26 27 28 |
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 25 def stop @monitor_thread.stop task_monitor.remove_process end |