From fdd9c25dc66a454c08afe8c5bbde577943c951e9 Mon Sep 17 00:00:00 2001 From: Mark Valentine Date: Thu, 3 Mar 2022 13:20:57 -0700 Subject: [PATCH] propogate replicate through the account_report process - currently we swap back to :report db even if upstream we timed out from using it and are using :secondary. Result is missed data in the output report. flag = none test plan: This is tricky to test as it is a race condition between primary and report db and requires report db to timeout on being up to date. For now, just verify specs pass and monitor if empty reports continue to happen in prod. Change-Id: I92f0024593cd497949747378b8c8792e4cc047b3 refs: PFS-18941 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/286338 Tested-by: Service Cloud Jenkins Reviewed-by: Matt Maruri QA-Review: Mark Valentine Product-Review: Mark Valentine --- .../lib/account_reports/report_helper.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gems/plugins/account_reports/lib/account_reports/report_helper.rb b/gems/plugins/account_reports/lib/account_reports/report_helper.rb index 120be1f0b0c..73a99983c4d 100644 --- a/gems/plugins/account_reports/lib/account_reports/report_helper.rb +++ b/gems/plugins/account_reports/lib/account_reports/report_helper.rb @@ -302,12 +302,12 @@ module AccountReports::ReportHelper ) end - def write_report(headers, enable_i18n_features = false, &block) - file = generate_and_run_report(headers, "csv", enable_i18n_features, &block) + def write_report(headers, enable_i18n_features = false, replica = :report, &block) + file = generate_and_run_report(headers, "csv", enable_i18n_features, replica, &block) GuardRail.activate(:primary) { send_report(file) } end - def generate_and_run_report(headers = nil, extension = "csv", enable_i18n_features = false) + def generate_and_run_report(headers = nil, extension = "csv", enable_i18n_features = false, replica = :report) file = AccountReports.generate_file(@account_report, extension) options = {} if enable_i18n_features @@ -316,7 +316,7 @@ module AccountReports::ReportHelper ExtendedCSV.open(file, "w", **options) do |csv| csv.instance_variable_set(:@account_report, @account_report) csv << headers unless headers.nil? - activate_report_db { yield csv } if block_given? + activate_report_db(replica: replica) { yield csv } if block_given? GuardRail.activate(:primary) { @account_report.update_attribute(:current_line, csv.lineno) } end file @@ -449,7 +449,7 @@ module AccountReports::ReportHelper def write_report_from_rows(headers, replica: :report) activate_report_db(replica: replica) do - write_report(headers) do |csv| + write_report(headers, false, replica) do |csv| @account_report.account_report_rows.order(:account_report_runner_id, :row_number) .find_in_batches(strategy: :cursor) do |batch| batch.each { |record| csv << record.row } @@ -463,7 +463,7 @@ module AccountReports::ReportHelper activate_report_db(replica: replica) do files.each do |file, headers_for_file| csvs[file] = if @account_report.account_report_rows.where(file: file).exists? - generate_and_run_report(headers_for_file) do |csv| + generate_and_run_report(headers_for_file, "csv", false, replica) do |csv| @account_report.account_report_rows.where(file: file) .order(:account_report_runner_id, :row_number) .find_in_batches(strategy: :cursor) do |batch| @@ -471,7 +471,7 @@ module AccountReports::ReportHelper end end else - generate_and_run_report(headers_for_file) + generate_and_run_report(headers_for_file, "csv", false, replica) end end end