lib/topological_inventory/schema/default.rb
# This method is bulk updating by raw SQL query
This method is bulk updating by raw SQL query
This method is bulk updating by raw SQL query
def service_instance_tasks_update_by_raw_sql(source)
        tasks_source_ref = Task.where(:state => 'running', :target_type => 'ServiceInstance', :source_id => source.id)
                         .pluck(:target_source_ref)
        return if tasks_source_ref.blank?
        svc_instances_values = ServiceInstance.where(:source_ref => tasks_source_ref)
                                              .pluck(:id, :archived_at, :external_url, :source_ref,
                                                     Arel.sql("extra->'finished'"),
                                                     Arel.sql("extra->'status'"),
                                                     Arel.sql("extra->'task_status'"),
                                                     Arel.sql("extra->'artifacts'"))
        return if svc_instances_values.blank?
        sql_update_values = []
        svc_instances_values.each do |attrs|
          id, archived_at, external_url, source_ref, finished_timestamp, status, task_status, artifacts = attrs[0], attrs[1], attrs[2], attrs[3], attrs[4], attrs[5], attrs[6], attrs[7]
          values = task_update_values(id, source_ref, external_url, status, artifacts, task_status, finished_timestamp, archived_at, source.id)
          sql_update_values << "('#{source_ref}', '#{values[:state]}', '#{values[:status]}', '#{values[:context].to_json}'::json)"
        end
        sql = <<SQL
              UPDATE tasks AS t SET
                state = c.state,
                status = c.status,
                context = c.context
              FROM (VALUES :values
              ) AS c(source_ref, state, status, context)
              WHERE t.target_source_ref = c.source_ref
                AND t.target_type = 'ServiceInstance';
SQL
        sql.sub!(':values', sql_update_values.join(','))
        ActiveRecord::Base.connection.execute(sql)
      end
def service_instance_tasks_update_by_raw_sql ( source ) tasks_source_ref = Task . where ( :state => 'running' , :target_type => 'ServiceInstance' , :source_id => source . id ) . pluck ( :target_source_ref ) return if tasks_source_ref . blank? svc_instances_values = ServiceInstance . where ( :source_ref => tasks_source_ref ) . pluck ( :id , :archived_at , :external_url , :source_ref , Arel . sql ( "extra->'finished'" ) , Arel . sql ( "extra->'status'" ) , Arel . sql ( "extra->'task_status'" ) , Arel . sql ( "extra->'artifacts'" ) ) return if svc_instances_values . blank? sql_update_values = [ ] svc_instances_values . each do | attrs | id , archived_at , external_url , source_ref , finished_timestamp , status , task_status , artifacts = attrs [ 0 ] , attrs [ 1 ] , attrs [ 2 ] , attrs [ 3 ] , attrs [ 4 ] , attrs [ 5 ] , attrs [ 6 ] , attrs [ 7 ] values = task_update_values ( id , source_ref , external_url , status , artifacts , task_status , finished_timestamp , archived_at , source . id ) sql_update_values << "('#{source_ref}', '#{values[:state]}', '#{values[:status]}', '#{values[:context].to_json}'::json)" end sql = <<SQL 
              UPDATE tasks AS t SET
                state = c.state,
                status = c.status,
                context = c.context
              FROM (VALUES :values
              ) AS c(source_ref, state, status, context)
              WHERE t.target_source_ref = c.source_ref
                AND t.target_type = 'ServiceInstance';
 SQL sql . sub! ( ':values' , sql_update_values . join ( ',' ) ) ActiveRecord :: Base . connection . execute ( sql ) end
This method is bulk updating by raw SQL query
This method is bulk updating by raw SQL query
# Get running tasks # Load saved service instances (IDs needed) # Preparing SQL update values from loaded ServiceInstances # Update query. # Pairs records by `Task.target_type` and `Task.target_source_ref`
source