Class: PatientHttp::Sidekiq::ProcessorObserver

Inherits:
ProcessorObserver
  • Object
show all
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.

Tasks are registered in the crash-recovery registry when the processor accepts them, before Processor#enqueue returns, so a request always has a durable record from the moment the caller hands it off. The entry is removed when the request completes or when a Sidekiq job owns the request again (the task was rejected or re-enqueued).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(processor) ⇒ ProcessorObserver

Returns a new instance of ProcessorObserver.



16
17
18
19
20
21
22
23
24
25
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 16

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.tracked_request_ids }
  )
end

Instance Attribute Details

#task_monitorObject (readonly)

Returns the value of attribute task_monitor.



14
15
16
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 14

def task_monitor
  @task_monitor
end

Instance Method Details

#capacity_exceededObject



36
37
38
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 36

def capacity_exceeded
  @stats.record_capacity_exceeded
end

#request_end(request_task) ⇒ Object



52
53
54
55
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 52

def request_end(request_task)
  task_monitor.unregister(request_task)
  @stats.record_request(request_task.response&.status, request_task.duration)
end

#request_enqueued(request_task) ⇒ Object



40
41
42
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 40

def request_enqueued(request_task)
  task_monitor.register(request_task)
end

#request_error(error) ⇒ Object



57
58
59
60
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 57

def request_error(error)
  error_type = error.is_a?(PatientHttp::Error) ? error.error_type : :exception
  @stats.record_error(error_type)
end

#request_rejected(request_task) ⇒ Object



44
45
46
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 44

def request_rejected(request_task)
  task_monitor.unregister(request_task)
end

#request_requeued(request_task) ⇒ Object



48
49
50
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 48

def request_requeued(request_task)
  task_monitor.unregister(request_task)
end

#startObject



27
28
29
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 27

def start
  @monitor_thread.start
end

#stopObject



31
32
33
34
# File 'lib/patient_http/sidekiq/processor_observer.rb', line 31

def stop
  @monitor_thread.stop
  task_monitor.remove_process
end