Class: DBOperations::UpdateOperationsStatsResumeWorker

Inherits:
HasUtils::GoodJob::BaseWorker
  • Object
show all
Includes:
HasHelpers::DefaultWorker
Defined in:
app/workers/has_helpers/db_operations/update_operations_stats_resume_worker.rb

Instance Method Summary collapse

Methods included from HasHelpers::DefaultWorker

included

Instance Method Details

#performObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/workers/has_helpers/db_operations/update_operations_stats_resume_worker.rb', line 9

def perform
  ::Rails.logger.info "Truncate db_operations_stats_resumes."

  ActiveRecord::Base.connection.execute <<-END_OF_SQL
    TRUNCATE db_operations_stats_resumes;
  END_OF_SQL

  ::Rails.logger.info "Start updating db_operations_stats_resumes"

  ActiveRecord::Base.connection.execute <<-END_OF_SQL
    INSERT INTO db_operations_stats_resumes
    SELECT relation_name || (executed_sql_json -> 'sql')::TEXT AS id,
           relation_name,
           MAX(created_at)                                     AS last_created_at,
           SUM(execute_duration)                               AS sum_duration,
           COUNT(relation_name)                                AS count_calls,
           executed_sql_json -> 'sql'                          AS executed_sql,
           MAX(execute_duration)                               AS max_duration
    FROM db_operations_stats
    GROUP BY relation_name,
             executed_sql_json -> 'sql';
  END_OF_SQL

  ::Rails.logger.info "Updated db_operations_stats_resumes"
end