Class: OpenC3::MultiMicroservice

Inherits:
Microservice show all
Defined in:
lib/openc3/microservices/multi_microservice.rb

Instance Attribute Summary

Attributes inherited from Microservice

#count, #custom, #error, #logger, #microservice_status_thread, #name, #scope, #secrets, #state

Instance Method Summary collapse

Methods inherited from Microservice

#as_json, #initialize, run

Constructor Details

This class inherits a constructor from OpenC3::Microservice

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/openc3/microservices/multi_microservice.rb', line 24

def run
  @threads = []
  ARGV.each do |microservice_name|
    microservice_model = MicroserviceModel.get_model(name: microservice_name, scope: @scope)
    @threads << Thread.new do
      cmd_line = microservice_model.cmd.join(' ')
      split_cmd_line = cmd_line.split(' ')
      filename = nil
      split_cmd_line.each do |item|
        if File.extname(item) == '.rb'
          filename = item
          break
        end
      end
      raise "Could not determine class filename from '#{cmd_line}'" unless filename
      OpenC3.set_working_dir(@work_dir) do
        require_relative filename
      end
      klass = filename.filename_to_class_name.to_class
      klass.run(microservice_model.name)
    end
  end
  @threads.each do |thread|
    thread.join
  end
end

#shutdownObject



51
52
53
54
55
56
57
58
# File 'lib/openc3/microservices/multi_microservice.rb', line 51

def shutdown
  super()
  if @threads
    @threads.each do |thread|
      thread.join
    end
  end
end