Class: OpenC3::NoScopeLogMessages

Inherits:
Migration show all
Defined in:
lib/openc3/migrations/20230915000002_no_scope_log_messages.rb

Class Method Summary collapse

Class Method Details

.runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/openc3/migrations/20230915000002_no_scope_log_messages.rb', line 6

def self.run
  # Add NOSCOPE topic to log message microservice for DEFAULT scope
  model = MicroserviceModel.get_model(name: "DEFAULT__OPENC3__LOG", scope: 'DEFAULT')
  if model
    model.topics = ["DEFAULT__openc3_log_messages", "NOSCOPE__openc3_log_messages"]
    model.update
  end

  ScopeModel.get_all_models(scope: nil).each do |scope, scope_model|
    parent = "#{scope}__SCOPEMULTI__#{scope}"

    # Remove NOTIFICATION log microservice from scopes
    model = MicroserviceModel.get_model(name: "#{scope}__NOTIFICATION__LOG", scope: scope)
    if model
      model.destroy
    end

    # Add Scope Cleanup microservice to scopes
    model = MicroserviceModel.get_model(name: "#{scope}__SCOPECLEANUP__#{scope}", scope: scope)
    unless model
      scope_model.deploy_scopecleanup_microservice("", {}, parent)
    end

    model = MicroserviceModel.get_model(name: parent, scope: scope)
    if model
      model.cmd.delete("#{scope}__NOTIFICATION__LOG")
      unless model.cmd.include?("#{scope}__SCOPECLEANUP__#{scope}")
        model.cmd << "#{scope}__SCOPECLEANUP__#{scope}"
      end
      model.update
    end
  end
end