Class: GoodJob::DenormalizationStatsWorker
- Inherits:
-
HasUtils::GoodJob::BaseWorker
- Object
- HasUtils::GoodJob::BaseWorker
- GoodJob::DenormalizationStatsWorker
- Includes:
- HasUtils::GoodJob::UniqueJob
- Defined in:
- app/workers/good_job/denormalization_stats_worker.rb
Constant Summary collapse
- STARTED =
"STARTED"- FINISHED =
"FINISHED"- LOCKED =
"LOCKED"- STAT_TYPE =
"denormalization"- STAT_SUBTYPE =
"denormalization_errors"
Instance Attribute Summary collapse
-
#starting_time ⇒ Object
readonly
Returns the value of attribute starting_time.
-
#stat ⇒ Object
readonly
Returns the value of attribute stat.
Instance Method Summary collapse
- #perform(table_name, error_query) ⇒ Object
- #process_table(_table_name, error_query) ⇒ Object
- #save_to_stats(name, _type, subtype, data, _starting_time, _ending_time = 0) ⇒ Object
Instance Attribute Details
#starting_time ⇒ Object (readonly)
Returns the value of attribute starting_time.
8 9 10 |
# File 'app/workers/good_job/denormalization_stats_worker.rb', line 8 def starting_time @starting_time end |
#stat ⇒ Object (readonly)
Returns the value of attribute stat.
8 9 10 |
# File 'app/workers/good_job/denormalization_stats_worker.rb', line 8 def stat @stat end |
Instance Method Details
#perform(table_name, error_query) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/workers/good_job/denormalization_stats_worker.rb', line 23 def perform(table_name, error_query) result = { count: 0, ids: [] } starting_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) save_to_stats(table_name, STAT_TYPE, STAT_SUBTYPE, { table: table_name, count: result[:count], status: STARTED, errors: nil }, starting_time, starting_time) begin result = process_table(table_name, error_query) rescue => e save_to_stats(table_name, STAT_TYPE, STAT_SUBTYPE, { table: table_name, count: result[:count], status: LOCKED, errors: e&. }, starting_time, ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)) return end save_to_stats(table_name, STAT_TYPE, STAT_SUBTYPE, { table: table_name, count: result[:count], status: FINISHED, errors: nil }, starting_time, ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)) # In case error counts are greater than zero, fix the related records if result[:count].present? && result[:ids].present? && result[:count] > 0 ::GoodJob::ConfigurableBackfill.perform_later([table_name.to_sym], ids_to_update: result[:ids]) end end |
#process_table(_table_name, error_query) ⇒ Object
41 42 43 44 45 46 |
# File 'app/workers/good_job/denormalization_stats_worker.rb', line 41 def process_table(_table_name, error_query) count_result = ::ActiveRecord::Base.connection.execute(error_query) count = count_result&.values&.size ids = count_result&.values&.flatten { count: count, ids: ids } end |
#save_to_stats(name, _type, subtype, data, _starting_time, _ending_time = 0) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'app/workers/good_job/denormalization_stats_worker.rb', line 48 def save_to_stats(name, _type, subtype, data, _starting_time, _ending_time = 0) stat = ::HasHelpers::Stat.new stat.name = name stat.maintype = "denormalization" stat.subtype = subtype stat.data = data stat.save! end |