Class: RailsConsoleAi::AgentRunner
- Inherits:
-
Object
- Object
- RailsConsoleAi::AgentRunner
- Defined in:
- lib/rails_console_ai/agent_runner.rb
Overview
Long-running worker that polls the sessions table for queued agent_api rows, claims them atomically, and runs each in its own Thread via ConversationEngine#one_shot. Started by ‘rake rails_console_ai:agents`.
Constant Summary collapse
- POLL_INTERVAL =
2.0- DEFAULT_CONCURRENCY =
3- DRAIN_TIMEOUT =
60
Instance Method Summary collapse
-
#initialize(concurrency: DEFAULT_CONCURRENCY, poll_interval: POLL_INTERVAL) ⇒ AgentRunner
constructor
A new instance of AgentRunner.
- #start ⇒ Object
Constructor Details
#initialize(concurrency: DEFAULT_CONCURRENCY, poll_interval: POLL_INTERVAL) ⇒ AgentRunner
Returns a new instance of AgentRunner.
18 19 20 21 22 23 24 |
# File 'lib/rails_console_ai/agent_runner.rb', line 18 def initialize(concurrency: DEFAULT_CONCURRENCY, poll_interval: POLL_INTERVAL) @concurrency = concurrency @poll_interval = poll_interval @threads = {} # session_id => Thread @mutex = Mutex.new @stopping = false end |
Instance Method Details
#start ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rails_console_ai/agent_runner.rb', line 26 def start $stdout.sync = true $stderr.sync = true $stdout = RailsConsoleAi::PrefixedIO.new($stdout) unless $stdout.is_a?(RailsConsoleAi::PrefixedIO) $stderr = RailsConsoleAi::PrefixedIO.new($stderr) unless $stderr.is_a?(RailsConsoleAi::PrefixedIO) install_signal_handlers puts "AgentRunner starting (concurrency=#{@concurrency}, poll=#{@poll_interval}s)" loop do break if @stopping reap_finished fill_slots sleep @poll_interval end drain puts "AgentRunner stopped." end |