Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
Save task's status with ServiceInstance's task status
Browse files Browse the repository at this point in the history
  • Loading branch information
slemrmartin committed Apr 15, 2020
1 parent 00ef271 commit b3e54f7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/topological_inventory/schema/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,30 @@ def add_service_instances
# Get running tasks
tasks_source_ref = Task.where(:state => 'running', :target_type => 'ServiceInstance', :source_id => source.id)
.pluck(:target_source_ref)
return if tasks_source_ref.blank?

# Load saved service instances (IDs needed)
svc_instances_values = ServiceInstance.where(:source_ref => tasks_source_ref).pluck(:id, :external_url, :source_ref, Arel.sql("extra->'finished'"), Arel.sql("extra->'status'"))
svc_instances_values = ServiceInstance.where(:source_ref => tasks_source_ref)
.pluck(:id, :external_url, :source_ref,
Arel.sql("extra->'finished'"),
Arel.sql("extra->'status'"),
Arel.sql("extra->'task_status'"))
return if svc_instances_values.blank?

# Preparing Tasks data for mass update
sql_update_values = []
svc_instances_values.each do |attrs|
id, external_url, source_ref, finished_timestamp, status = attrs[0], attrs[1], attrs[2], attrs[3], attrs[4]
id, external_url, source_ref, finished_timestamp, status, task_status = attrs[0], attrs[1], attrs[2], attrs[3], attrs[4], attrs[5]

state = finished_timestamp.blank? ? 'running' : 'completed'
status = %w[error failed].include?(status) ? 'error' : 'ok' # TODO: ansible-tower specific, normalize in collector
context = {
:remote_status => status,
:service_instance => {
:id => id,
:url => external_url
:id => id,
:job_status => status,
:url => external_url,
}
}.to_json
sql_update_values << "('#{source_ref}', '#{state}', '#{status}', '#{context}'::json)"
sql_update_values << "('#{source_ref}', '#{state}', '#{task_status}', '#{context}'::json)"
end

sql = <<SQL
Expand Down

0 comments on commit b3e54f7

Please sign in to comment.