Class: ActiveMatrix::Daemon::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/active_matrix/daemon/worker.rb

Overview

Worker process that runs a subset of agents

Each worker is a forked child process that:

  • Initializes its own AgentManager

  • Runs only assigned agents (by ID)

  • Handles signals for graceful shutdown

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index:, agent_ids:) ⇒ Worker

Returns a new instance of Worker.



15
16
17
18
19
# File 'lib/active_matrix/daemon/worker.rb', line 15

def initialize(index:, agent_ids:)
  @index = index
  @agent_ids = agent_ids
  @running = false
end

Instance Attribute Details

#agent_idsObject (readonly)

Returns the value of attribute agent_ids.



13
14
15
# File 'lib/active_matrix/daemon/worker.rb', line 13

def agent_ids
  @agent_ids
end

#indexObject (readonly)

Returns the value of attribute index.



13
14
15
# File 'lib/active_matrix/daemon/worker.rb', line 13

def index
  @index
end

Instance Method Details

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_matrix/daemon/worker.rb', line 21

def run
  @running = true

  set_process_name
  install_signal_handlers
  reconnect_database

  logger.info "Worker #{index} starting with agents: #{agent_ids.join(', ')}"

  run_agents
rescue StandardError => e
  logger.error "Worker #{index} crashed: #{e.message}"
  logger.error e.backtrace.join("\n")
  raise
ensure
  logger.info "Worker #{index} exiting"
end