Class: SolidObjects::Supervisor
- Inherits:
-
Object
- Object
- SolidObjects::Supervisor
- Defined in:
- lib/solid_objects/supervisor.rb,
sig/generated/lib/solid_objects/supervisor.rbs
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Instance Method Summary collapse
- #build_components(worker_count:, effect_worker_count:, broadcast_worker_count:, reminder_scheduler_count:) ⇒ Array[Worker | EffectExecutor | ReminderScheduler | BroadcastExecutor]
-
#initialize(worker_count: SolidObjects.configuration.worker_count, effect_worker_count: SolidObjects.configuration.effect_worker_count, broadcast_worker_count: SolidObjects.configuration.broadcast_worker_count, reminder_scheduler_count: SolidObjects.configuration.reminder_scheduler_count) ⇒ Supervisor
constructor
A new instance of Supervisor.
- #join_until_timeout ⇒ void
- #monotonic_now ⇒ Float
- #run ⇒ void
- #start ⇒ void
- #stop ⇒ void
Constructor Details
#initialize(worker_count: SolidObjects.configuration.worker_count, effect_worker_count: SolidObjects.configuration.effect_worker_count, broadcast_worker_count: SolidObjects.configuration.broadcast_worker_count, reminder_scheduler_count: SolidObjects.configuration.reminder_scheduler_count) ⇒ Supervisor
Returns a new instance of Supervisor.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/solid_objects/supervisor.rb', line 10 def initialize( worker_count: SolidObjects.configuration.worker_count, effect_worker_count: SolidObjects.configuration.effect_worker_count, broadcast_worker_count: SolidObjects.configuration.broadcast_worker_count, reminder_scheduler_count: SolidObjects.configuration.reminder_scheduler_count ) @components = build_components( worker_count:, effect_worker_count:, broadcast_worker_count:, reminder_scheduler_count: ) @threads = [] @started = false end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
56 57 58 |
# File 'lib/solid_objects/supervisor.rb', line 56 def components @components end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
56 57 58 |
# File 'lib/solid_objects/supervisor.rb', line 56 def threads @threads end |
Instance Method Details
#build_components(worker_count:, effect_worker_count:, broadcast_worker_count:, reminder_scheduler_count:) ⇒ Array[Worker | EffectExecutor | ReminderScheduler | BroadcastExecutor]
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/solid_objects/supervisor.rb', line 59 def build_components( worker_count:, effect_worker_count:, broadcast_worker_count:, reminder_scheduler_count: ) Array.new(worker_count) { Worker.new } + Array.new(effect_worker_count) { EffectExecutor.new } + Array.new(broadcast_worker_count) { BroadcastExecutor.new } + Array.new(reminder_scheduler_count) { ReminderScheduler.new } end |
#join_until_timeout ⇒ void
This method returns an undefined value.
72 73 74 75 76 77 78 79 80 |
# File 'lib/solid_objects/supervisor.rb', line 72 def join_until_timeout deadline = monotonic_now + SolidObjects.configuration.shutdown_timeout threads.each do |thread| remaining = deadline - monotonic_now break unless remaining.positive? thread.join(remaining) end end |
#monotonic_now ⇒ Float
83 84 85 |
# File 'lib/solid_objects/supervisor.rb', line 83 def monotonic_now ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) end |
#run ⇒ void
This method returns an undefined value.
27 28 29 30 31 32 |
# File 'lib/solid_objects/supervisor.rb', line 27 def run start threads.each(&:join) ensure stop end |
#start ⇒ void
This method returns an undefined value.
35 36 37 38 39 40 41 |
# File 'lib/solid_objects/supervisor.rb', line 35 def start return if @started @started = true @threads = components.map { |component| Thread.new { component.run } } SolidObjects.instrument(:"supervisor.started", component_count: components.length) end |
#stop ⇒ void
This method returns an undefined value.
44 45 46 47 48 49 50 51 52 |
# File 'lib/solid_objects/supervisor.rb', line 44 def stop return unless @started components.each(&:request_shutdown) join_until_timeout components.reject(&:stopped?).each(&:stop) @started = false SolidObjects.instrument(:"supervisor.stopped", component_count: components.length) end |