313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
# File 'lib/openc3/microservices/reaction_microservice.rb', line 313
def run_script(reaction:, action:)
Logger.debug "ReactionWorker-#{@ident} running reaction #{reaction.name}, script: '#{action['value']}'"
begin
request = Net::HTTP::Post.new(
"/script-api/scripts/#{action['value']}/run?scope=#{@scope}",
'Content-Type' => 'application/json',
'Authorization' => @authentication.token()
)
request.body = JSON.generate({
'scope' => @scope,
'environment' => action['environment'],
'reaction' => reaction.name,
'id' => Time.now.to_i
})
hostname = ENV['OPENC3_SCRIPT_HOSTNAME'] || 'openc3-script-runner-api'
response = Net::HTTP.new(hostname, 2902).request(request)
raise "failed to call #{hostname}, for script: #{action['value']}, response code: #{response.code}" if response.code != '200'
Logger.info "ReactionWorker-#{@ident} #{reaction.name} script action complete, #{action['value']} => #{response.body}"
rescue StandardError => e
Logger.error "ReactionWorker-#{@ident} #{reaction.name} script action failed, #{action}\n#{e.message}"
end
end
|