topological_inventory-core 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bafb3cb3b7789833d6fafd71e34da8e172039ae49f7fe03a16fac40cba7be4e
4
- data.tar.gz: e642d51826923f406e0a24ca75ea57fea47af01386217b7c1d240e0dad7dded1
3
+ metadata.gz: f21975a8fa7c70cc86652d785d716fecf06a041cf026ddce127e054b8d0c986e
4
+ data.tar.gz: 44c0d4d9b04428595ddc3e65aeee23a3c25545eb79e30a30250ced459836e81c
5
5
  SHA512:
6
- metadata.gz: 4728c1a6494e41e969d034f14ad64bd4bdb2ec1b1c2ce16bc61d00d327ae49b4fbde05d23dc313b773bb2b261af791b0882ab4803626b785e069f4e4e5f7bcf1
7
- data.tar.gz: ac02e6f01322313ece2855c8876a3ae9224cf23a7c3bf86da66a597df76ee8affcfd43aef48693dc30752a8a9fce5b4df1035df08ba39e7beb9d7e4746b9b347
6
+ metadata.gz: 7a168d488512df3ef0255ed3b40411fc5558125795c4665dcb9cad05a17c691732a7cb369246ccbf60c8703951a6535fb3912dfb8c3847ab28c6ecfc7ae420e5
7
+ data.tar.gz: 908b091ddb826197916a77a80d182ad1035586c653ca80ce7313e8e19d6c11256567f4593a99a59bad40d5b2690a8328055ff74a891c20856b734be296649bd7
@@ -0,0 +1,5 @@
1
+ class AddRequestIdToTask < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :tasks, :x_rh_insights_request, :string
4
+ end
5
+ end
data/db/schema.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2020_04_14_123737) do
13
+ ActiveRecord::Schema.define(version: 2020_04_28_090420) do
14
14
 
15
15
  # These are extensions that must be enabled in order to support this database
16
16
  enable_extension "plpgsql"
@@ -1190,6 +1190,7 @@ ActiveRecord::Schema.define(version: 2020_04_14_123737) do
1190
1190
  t.string "target_source_ref"
1191
1191
  t.string "target_type"
1192
1192
  t.bigint "source_id"
1193
+ t.string "x_rh_insights_request"
1193
1194
  t.index ["source_id"], name: "index_tasks_on_source_id"
1194
1195
  t.index ["target_type", "target_source_ref"], name: "index_tasks_on_target_type_and_target_source_ref"
1195
1196
  t.index ["tenant_id"], name: "index_tasks_on_tenant_id"
@@ -1,5 +1,5 @@
1
1
  module TopologicalInventory
2
2
  module Core
3
- VERSION = '1.1.1'
3
+ VERSION = '1.1.2'
4
4
  end
5
5
  end
@@ -147,11 +147,11 @@ module TopologicalInventory
147
147
  return if src_refs.blank?
148
148
 
149
149
  # Updating Tasks
150
- # service_instance_tasks_update_effective(source)
151
- service_instance_tasks_update_ineffective(source, src_refs)
150
+ # service_instance_tasks_update_by_raw_sql(source)
151
+ service_instance_tasks_update_by_activerecord(tasks_collection, source, src_refs)
152
152
  end
153
153
 
154
- def task_update_values(svc_instance_id, external_url, status, task_status, finished_timestamp)
154
+ def task_update_values(svc_instance_id, source_ref, external_url, status, task_status, finished_timestamp, source_id)
155
155
  {
156
156
  :state => finished_timestamp.blank? ? 'running' : 'completed',
157
157
  :status => task_status,
@@ -159,6 +159,8 @@ module TopologicalInventory
159
159
  :service_instance => {
160
160
  :id => svc_instance_id,
161
161
  :job_status => status,
162
+ :source_id => source_id,
163
+ :source_ref => source_ref,
162
164
  :url => external_url
163
165
  }
164
166
  }
@@ -166,24 +168,29 @@ module TopologicalInventory
166
168
  end
167
169
 
168
170
  # This method is updating one by one using ActiveRecord
169
- def service_instance_tasks_update_ineffective(source, svc_instances_source_ref)
171
+ def service_instance_tasks_update_by_activerecord(tasks_collection, source, svc_instances_source_ref)
170
172
  service_instances = ServiceInstance.where(:source_id => source.id, :source_ref => svc_instances_source_ref)
171
173
  tasks_by_source_ref = Task.where(:state => 'running', :target_type => 'ServiceInstance', :source_id => source.id, :target_source_ref => service_instances.pluck(:source_ref)).index_by(&:target_source_ref)
172
174
 
173
175
  service_instances.select(:id, :external_url, :source_ref, :extra).find_in_batches do |group|
174
176
  ActiveRecord::Base.transaction do
175
177
  group.each do |svc_instance|
176
- next if tasks_by_source_ref[svc_instance.source_ref].nil?
178
+ next if (task = tasks_by_source_ref[svc_instance.source_ref]).nil?
177
179
 
178
- values = task_update_values(svc_instance.id, svc_instance.external_url, svc_instance.extra['status'], svc_instance.extra['task_status'], svc_instance.extra['finished'])
179
- tasks_by_source_ref[svc_instance.source_ref].update(values)
180
+ values = task_update_values(svc_instance.id, svc_instance.source_ref, svc_instance.external_url, svc_instance.extra['status'], svc_instance.extra['task_status'], svc_instance.extra['finished'], source.id)
181
+ # 1) Updating Task
182
+ task.update(values)
183
+
184
+ # 2) Saving to updated records (will be published in Kafka)
185
+ # - see topological_inventory-persister:Workflow.send_task_updates_to_queue!
186
+ tasks_collection.updated_records << values.merge(:id => task.id, :x_rh_insights_request => task.x_rh_insights_request)
180
187
  end
181
188
  end
182
189
  end
183
190
  end
184
191
 
185
192
  # This method is bulk updating by raw SQL query
186
- def service_instance_tasks_update_effective(source)
193
+ def service_instance_tasks_update_by_raw_sql(source)
187
194
  # Get running tasks
188
195
  tasks_source_ref = Task.where(:state => 'running', :target_type => 'ServiceInstance', :source_id => source.id)
189
196
  .pluck(:target_source_ref)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topological_inventory-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Grare
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-22 00:00:00.000000000 Z
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_tenant
@@ -354,6 +354,7 @@ files:
354
354
  - db/migrate/20200317082640_add_tracking_timestamps_to_refresh_state.rb
355
355
  - db/migrate/20200403114310_add_target_and_source_to_task.rb
356
356
  - db/migrate/20200414123737_extract_tasks_source_ref_from_context.rb
357
+ - db/migrate/20200428090420_add_request_id_to_task.rb
357
358
  - db/schema.rb
358
359
  - db/seeds.rb
359
360
  - lib/tasks/topological_inventory_tasks.rake