Class: Wal::Runner
- Inherits:
-
Object
- Object
- Wal::Runner
- Defined in:
- lib/wal/runner.rb
Defined Under Namespace
Classes: Worker
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#db_config ⇒ Object
readonly
Returns the value of attribute db_config.
Instance Method Summary collapse
-
#initialize(config:, db_config:) ⇒ Runner
constructor
A new instance of Runner.
- #run_forked_workers(workers_slots) ⇒ Object
- #run_single_worker(worker_name, slot_configs) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(config:, db_config:) ⇒ Runner
Returns a new instance of Runner.
92 93 94 95 96 |
# File 'lib/wal/runner.rb', line 92 def initialize(config:, db_config:) @config = config @db_config = db_config @child_pids = [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
90 91 92 |
# File 'lib/wal/runner.rb', line 90 def config @config end |
#db_config ⇒ Object (readonly)
Returns the value of attribute db_config.
90 91 92 |
# File 'lib/wal/runner.rb', line 90 def db_config @db_config end |
Instance Method Details
#run_forked_workers(workers_slots) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/wal/runner.rb', line 115 def run_forked_workers(workers_slots) Wal.hooks[:before_fork]&.call(workers_slots) workers_slots.each do |worker_name, slot_configs| pid = fork_worker(worker_name, slot_configs) @child_pids << pid puts "[#{worker_name}] Spawned worker '#{worker_name}' with PID #{pid}" end @ping_thread = start_ping_thread setup_signal_handlers wait_for_workers end |
#run_single_worker(worker_name, slot_configs) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/wal/runner.rb', line 108 def run_single_worker((worker_name, slot_configs)) @ping_thread = start_ping_thread puts "[#{worker_name}] Starting worker process (PID: #{Process.pid})" worker = Worker.new(name: worker_name, slot_configs: slot_configs, db_config: db_config) worker.run end |
#start ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/wal/runner.rb', line 98 def start workers_slots = config["slots"].group_by { |_slot, slot_config| slot_config["worker"] || "default" } if workers_slots.size == 1 run_single_worker(workers_slots.first) else run_forked_workers(workers_slots) end end |