Skip to content

Commit f6b4909

Browse files
authored
HYC-1990 - Download Stat Remediation Utility (#1131)
* utility for remediating download stats * error handling * update logging * default value * update initial count
1 parent 2c78945 commit f6b4909

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
desc 'Fix hyc_download_stats work_id mismatch'
3+
task fix_hyc_download_stats_work_id_mismatch: :environment do
4+
puts 'Starting to fix hyc_download_stats work_id mismatches...'
5+
# Retrieve where work_id is equal to fileset_id
6+
download_stats = HycDownloadStat.where('work_id = fileset_id')
7+
initial_count = download_stats.count
8+
9+
updated = 0
10+
download_stats.each do |download_stat|
11+
# Retrieve the work data for the fileset id
12+
work_data = WorkUtilsHelper.fetch_work_data_by_fileset_id(download_stat.fileset_id)
13+
14+
begin
15+
# Update the download stat with the work id
16+
download_stat.update!(work_id: work_data[:work_id] || 'Unknown')
17+
updated += 1
18+
rescue StandardError => e
19+
# Log any errors encountered during the update
20+
puts "Failed to update HycDownloadStat ID #{download_stat.id}: #{e.message}"
21+
end
22+
end
23+
puts 'Completed fixing hyc_download_stats work_id mismatches.'
24+
puts "Successfully updated #{updated} records out of #{initial_count} attempted."
25+
end

0 commit comments

Comments
 (0)