85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/openc3/utilities/process_manager.rb', line 85
def monitor
processes_to_delete = []
cleanup_time = Time.now
while true
current_time = Time.now
@processes.each do |process|
if !process.alive?
output = process.
process.status.output = output
if process.exit_code != 0
process.status.state = "Crashed"
elsif output.include?('"level":"ERROR"')
process.status.state = "Error"
elsif output.include?('"level":"WARN"')
process.status.state = "Warning"
else
process.status.state = "Complete"
end
process.hard_stop
processes_to_delete << process
elsif process.expires_at < current_time
process.status.state = "Expired"
output = process.
process.status.output = output
process.hard_stop
processes_to_delete << process
end
process.status.update
end
processes_to_delete.each do |process|
message = "Process #{process.status.name}:#{process.process_type}:#{process.detail} completed with state #{process.status.state}\nProcess Output:\n#{process.status.output}"
if process.status.state != "Complete"
if process.status.state == "Warning"
Logger.warn(message, scope: process.scope)
else
Logger.error(message, scope: process.scope)
end
else
Logger.info(message, scope: process.scope)
end
@processes.delete(process)
end
processes_to_delete.clear
if (current_time - cleanup_time) > CLEANUP_CYCLE_SECONDS
scopes = ScopeModel.names
scopes.each do |scope|
statuses = ProcessStatusModel.get_all_models(scope: scope)
statuses.each do |_status_name, status|
if (current_time - Time.from_nsec_from_epoch(status.updated_at)) > CLEANUP_CYCLE_SECONDS
status.destroy
end
end
end
end
sleep(MONITOR_CYCLE_SECONDS)
end
end
|