Skip to content

Commit 932a744

Browse files
committed
Adds a report for version mismatches.
refs #5074
1 parent 3156cb5 commit 932a744

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

app/reports/preservation_versions.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# frozen_string_literal: true
2+
3+
# Compare SDR versions against Preservation versions
4+
# https://github.com/sul-dlss/dor-services-app/issues/5074
5+
# Invoke via:
6+
# bin/rails r -e production "PreservationVersions.report"
7+
class PreservationVersions
8+
def self.report
9+
new.report
10+
end
11+
12+
def report
13+
data = RepositoryObject.joins(:head_version).pluck(:external_identifier, :version)
14+
15+
progress_bar = tty_progress_bar(data.length)
16+
progress_bar.start
17+
18+
results = Parallel.map(data.each_slice(10000),
19+
in_processes: 4,
20+
finish: ->(finish_data, _, _) { progress_bar.advance(finish_data.length) }) do |data_slice|
21+
data_slice.map do |druid, version|
22+
begin
23+
preservation_version = Preservation::Client.objects.current_version(druid)
24+
rescue Preservation::Client::NotFoundError
25+
preservation_version = nil
26+
end
27+
preservation_version == version ? nil : [druid, version, preservation_version]
28+
end
29+
end.flatten(1).compact
30+
31+
CSV.open('preservation_versions_report.csv', 'w') do |csv|
32+
csv << %w[druid version preservation_version]
33+
results.each { |result| csv << result }
34+
end
35+
end
36+
37+
def tty_progress_bar(count)
38+
TTY::ProgressBar.new(
39+
'[:bar] (:percent (:current/:total), rate: :rate/s, mean rate: :mean_rate/s, :elapsed total, ETA: :eta_time)',
40+
bar_format: :box,
41+
advance: num_for_progress_advance(count),
42+
total: count
43+
)
44+
end
45+
46+
def num_for_progress_advance(count)
47+
return 1 if count < 100
48+
49+
count / 100
50+
end
51+
end

0 commit comments

Comments
 (0)