Class: GoodJob::ConfigurableBackfill

Inherits:
HasUtils::GoodJob::BaseWorker
  • Object
show all
Includes:
HasUtils::GoodJob::UniqueJob
Defined in:
app/workers/good_job/configurable_backfill.rb

Constant Summary collapse

STARTED =
"STARTED"
FINISHED =
"FINISHED"
LOCKED =
"LOCKED"
STAT_TYPE =
"denormalization"
STAT_SUBTYPE =
"configurable_backfill"
COLUMNS_DENORMALIZED =
{
  texts: "::GoodJob::DN::BackfillTextDenormalization"
}

Instance Method Summary collapse

Instance Method Details

#backfill_run(backfill_name, **options) ⇒ Object



50
51
52
53
# File 'app/workers/good_job/configurable_backfill.rb', line 50

def backfill_run(backfill_name, **options)
  # execute the backfills corresponding to the resource
  backfill_name.classify.constantize.new.run(**options)
end

#backfill_tables(table_names, **options) ⇒ Object



44
45
46
47
48
# File 'app/workers/good_job/configurable_backfill.rb', line 44

def backfill_tables(table_names, **options)
  table_names.each do |table_name|
    backfill_run(COLUMNS_DENORMALIZED[table_name.to_sym], **options)
  end
end

#perform(table_names = [], options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'app/workers/good_job/configurable_backfill.rb', line 32

def perform(table_names = [], options = {})
  starting_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
  save_to_stats(table_names, STAT_TYPE, STAT_SUBTYPE, { table: table_names, options: options, status: STARTED, errors: nil }, starting_time, starting_time)
  begin
    backfill_tables(table_names, **options)
  rescue => e
    save_to_stats(table_names, STAT_TYPE, STAT_SUBTYPE, { table: table_names, options: options, status: LOCKED, errors: e&.message }, starting_time, ::Process.clock_gettime(::Process::CLOCK_MONOTONIC))
    return
  end
  save_to_stats(table_names, STAT_TYPE, STAT_SUBTYPE, { table: table_names, options: options, status: FINISHED, errors: nil }, starting_time, ::Process.clock_gettime(::Process::CLOCK_MONOTONIC))
end

#save_to_stats(name, type, subtype, data, _starting_time, _ending_time = 0) ⇒ Object



55
56
57
58
59
60
61
62
# File 'app/workers/good_job/configurable_backfill.rb', line 55

def save_to_stats(name, type, subtype, data, _starting_time, _ending_time = 0)
  stat = ::HasHelpers::Stat.new
  stat.name = name
  stat.maintype = type
  stat.subtype = subtype
  stat.data = data
  stat.save!
end