Class: PatientHttp::Sidekiq::TaskMonitorThread
- Inherits:
-
Object
- Object
- PatientHttp::Sidekiq::TaskMonitorThread
- Includes:
- TimeHelper
- Defined in:
- lib/patient_http/sidekiq/task_monitor_thread.rb
Overview
Background thread that maintains heartbeats and performs garbage collection for in-flight HTTP requests.
Constant Summary collapse
- MAX_MONITOR_SLEEP =
Minimum seconds to sleep between monitor thread checks
5.0
Instance Attribute Summary collapse
-
#config ⇒ Configuration
readonly
The configuration object.
-
#task_monitor ⇒ TaskMonitor
readonly
The inflight request registry.
Instance Method Summary collapse
-
#initialize(config, task_monitor, inflight_ids_callback) ⇒ void
constructor
Initialize the monitor thread.
-
#running? ⇒ Boolean
Check if monitor thread is running.
-
#start ⇒ void
Start the monitor thread.
-
#stop ⇒ void
Stop the monitor thread.
Constructor Details
#initialize(config, task_monitor, inflight_ids_callback) ⇒ void
Initialize the monitor thread.
25 26 27 28 29 30 31 32 |
# File 'lib/patient_http/sidekiq/task_monitor_thread.rb', line 25 def initialize(config, task_monitor, inflight_ids_callback) @config = config @task_monitor = task_monitor @inflight_ids_callback = inflight_ids_callback @thread = nil @running = Concurrent::AtomicBoolean.new(false) @stop_signal = Concurrent::Event.new end |
Instance Attribute Details
#config ⇒ Configuration (readonly)
Returns the configuration object.
14 15 16 |
# File 'lib/patient_http/sidekiq/task_monitor_thread.rb', line 14 def config @config end |
#task_monitor ⇒ TaskMonitor (readonly)
Returns the inflight request registry.
17 18 19 |
# File 'lib/patient_http/sidekiq/task_monitor_thread.rb', line 17 def task_monitor @task_monitor end |
Instance Method Details
#running? ⇒ Boolean
Check if monitor thread is running.
69 70 71 |
# File 'lib/patient_http/sidekiq/task_monitor_thread.rb', line 69 def running? @running.true? end |
#start ⇒ void
This method returns an undefined value.
Start the monitor thread.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/patient_http/sidekiq/task_monitor_thread.rb', line 37 def start return if @running.true? @running.make_true @stop_signal.reset @task_monitor.ping_process @thread = Thread.new do run rescue => e # Log error but don't crash @config.logger&.error("[PatientHttp::Sidekiq] Monitor error: #{e.}\n#{e.backtrace.join("\n")}") raise if ::Sidekiq.testing? end @thread.name = "patient-http-monitor" end |
#stop ⇒ void
This method returns an undefined value.
Stop the monitor thread.
58 59 60 61 62 63 64 |
# File 'lib/patient_http/sidekiq/task_monitor_thread.rb', line 58 def stop @running.make_false @stop_signal.set # Interrupt the sleep immediately @thread&.join(1) @thread&.kill if @thread&.alive? @thread = nil end |