Class: StellarCoreCommander::Commander
- Inherits:
-
Object
- Object
- StellarCoreCommander::Commander
- Includes:
- Contracts
- Defined in:
- lib/stellar_core_commander/commander.rb
Overview
Commander is the object that manages running stellar-core processes. It is responsible for creating and cleaning Process objects
Instance Method Summary collapse
- #cleanup ⇒ Object
- #cleanup_at_exit! ⇒ Object
-
#initialize(process_type, process_options = {}) ⇒ Commander
constructor
A new instance of Commander.
-
#make_process ⇒ Object
make_process returns a new, unlaunched Process object, bound to a new tmpdir and.
Constructor Details
#initialize(process_type, process_options = {}) ⇒ Commander
Returns a new instance of Commander.
15 16 17 18 19 |
# File 'lib/stellar_core_commander/commander.rb', line 15 def initialize(process_type, ={}) @process_type = process_type @process_options = @processes = [] end |
Instance Method Details
#cleanup ⇒ Object
46 47 48 |
# File 'lib/stellar_core_commander/commander.rb', line 46 def cleanup @processes.each(&:cleanup) end |
#cleanup_at_exit! ⇒ Object
50 51 52 53 54 55 |
# File 'lib/stellar_core_commander/commander.rb', line 50 def cleanup_at_exit! at_exit do $stderr.puts "cleaning up #{@processes.length} processes" cleanup end end |
#make_process ⇒ Object
make_process returns a new, unlaunched Process object, bound to a new tmpdir and
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/stellar_core_commander/commander.rb', line 25 def make_process tmpdir = Dir.mktmpdir("scc") identity = Stellar::KeyPair.random base_port = 39132 + @processes.map(&:required_ports).sum process_class = case @process_type when 'local' LocalProcess when 'docker' DockerProcess else raise "Unknown process type: #{@process_type}" end process_class.new(tmpdir, base_port, identity, @process_options).tap do |p| p.setup @processes << p end end |