Class: PatientHttp::SolidQueue::TaskMonitorThread
- Inherits:
-
Object
- Object
- PatientHttp::SolidQueue::TaskMonitorThread
- Includes:
- TimeHelper
- Defined in:
- lib/patient_http/solid_queue/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 =
Maximum 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) ⇒ TaskMonitorThread
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) ⇒ TaskMonitorThread
Initialize the monitor thread.
24 25 26 27 28 29 30 31 |
# File 'lib/patient_http/solid_queue/task_monitor_thread.rb', line 24 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/solid_queue/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/solid_queue/task_monitor_thread.rb', line 17 def task_monitor @task_monitor end |
Instance Method Details
#running? ⇒ Boolean
Check if monitor thread is running.
67 68 69 |
# File 'lib/patient_http/solid_queue/task_monitor_thread.rb', line 67 def running? @running.true? end |
#start ⇒ void
This method returns an undefined value.
Start the monitor thread.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/patient_http/solid_queue/task_monitor_thread.rb', line 36 def start return if @running.true? @running.make_true @stop_signal.reset @task_monitor.ping_process @thread = Thread.new do run rescue => e @config.logger&.error("[PatientHttp::SolidQueue] Monitor error: #{e.}\n#{e.backtrace.join("\n")}") raise if PatientHttp.testing? end @thread.name = "async-http-monitor" end |
#stop ⇒ void
This method returns an undefined value.
Stop the monitor thread.
56 57 58 59 60 61 62 |
# File 'lib/patient_http/solid_queue/task_monitor_thread.rb', line 56 def stop @running.make_false @stop_signal.set @thread&.join(1) @thread&.kill if @thread&.alive? @thread = nil end |