Skip to content

Commit

Permalink
HYC-1990 - Download Stat Remediation Utility (#1131)
Browse files Browse the repository at this point in the history
* utility for remediating download stats

* error handling

* update logging

* default value

* update initial count
  • Loading branch information
davidcam-src authored Nov 14, 2024
1 parent 2c78945 commit f6b4909
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/tasks/fix_hyc_download_stats_work_id_mismatch.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true
desc 'Fix hyc_download_stats work_id mismatch'
task fix_hyc_download_stats_work_id_mismatch: :environment do
puts 'Starting to fix hyc_download_stats work_id mismatches...'
# Retrieve where work_id is equal to fileset_id
download_stats = HycDownloadStat.where('work_id = fileset_id')
initial_count = download_stats.count

updated = 0
download_stats.each do |download_stat|
# Retrieve the work data for the fileset id
work_data = WorkUtilsHelper.fetch_work_data_by_fileset_id(download_stat.fileset_id)

begin
# Update the download stat with the work id
download_stat.update!(work_id: work_data[:work_id] || 'Unknown')
updated += 1
rescue StandardError => e
# Log any errors encountered during the update
puts "Failed to update HycDownloadStat ID #{download_stat.id}: #{e.message}"
end
end
puts 'Completed fixing hyc_download_stats work_id mismatches.'
puts "Successfully updated #{updated} records out of #{initial_count} attempted."
end

0 comments on commit f6b4909

Please sign in to comment.