Module: RubyLLM::Toolbox::ProcessRegistry
- Defined in:
- lib/ruby_llm/toolbox/process_registry.rb
Overview
Thread-safe registry of background processes, shared across tool calls. Holds an upper bound on concurrent live processes and cleans everything up at interpreter exit so nothing is orphaned.
Defined Under Namespace
Classes: LimitError
Class Method Summary collapse
- .all ⇒ Object
- .delete(id) ⇒ Object
- .get(id) ⇒ Object
- .kill_all ⇒ Object
- .reset! ⇒ Object
- .start(argv:, env:, chdir:, name:, rlimits: {}, max: 8) ⇒ Object
Class Method Details
.all ⇒ Object
205 206 207 |
# File 'lib/ruby_llm/toolbox/process_registry.rb', line 205 def all @mutex.synchronize { @procs.values.dup } end |
.delete(id) ⇒ Object
209 210 211 |
# File 'lib/ruby_llm/toolbox/process_registry.rb', line 209 def delete(id) @mutex.synchronize { @procs.delete(id) } end |
.get(id) ⇒ Object
201 202 203 |
# File 'lib/ruby_llm/toolbox/process_registry.rb', line 201 def get(id) @mutex.synchronize { @procs[id] } end |
.kill_all ⇒ Object
213 214 215 |
# File 'lib/ruby_llm/toolbox/process_registry.rb', line 213 def kill_all all.each { |proc| proc.kill(grace: 0.2) } end |
.reset! ⇒ Object
217 218 219 220 |
# File 'lib/ruby_llm/toolbox/process_registry.rb', line 217 def reset! all.each { |proc| proc.kill(grace: 0.2) } @mutex.synchronize { @procs = {} } end |
.start(argv:, env:, chdir:, name:, rlimits: {}, max: 8) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/ruby_llm/toolbox/process_registry.rb', line 189 def start(argv:, env:, chdir:, name:, rlimits: {}, max: 8) @mutex.synchronize do live = @procs.values.count(&:running?) raise LimitError, "too many background processes (limit #{max}); kill some first" if live >= max @counter += 1 id = "proc_#{@counter}" @procs[id] = ManagedProcess.new(id: id, argv: argv, env: env, chdir: chdir, name: name, rlimits: rlimits) id end end |