Skip to content

Commit 0f766fb

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

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

app/reports/preservation_versions.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
# Objects with a closed version, indicating they have been accessioned.
14+
data = RepositoryObject.joins(:head_version).where.not(last_closed_version: nil).pluck(:external_identifier, :version)
15+
16+
progress_bar = tty_progress_bar(data.length)
17+
progress_bar.start
18+
19+
results = Parallel.map(data.each_slice(2500),
20+
in_processes: 3,
21+
finish: ->(finish_data, _, _) { progress_bar.advance(finish_data.length) }) do |data_slice|
22+
data_slice.map do |druid, version|
23+
begin
24+
preservation_version = Preservation::Client.objects.current_version(druid)
25+
rescue Preservation::Client::NotFoundError
26+
preservation_version = nil
27+
end
28+
preservation_version == version ? nil : [druid, version, preservation_version]
29+
end
30+
end.flatten(1).compact
31+
32+
CSV.open('preservation_versions_report.csv', 'w') do |csv|
33+
csv << %w[druid version preservation_version]
34+
results.each { |result| csv << result }
35+
end
36+
end
37+
38+
def tty_progress_bar(count)
39+
TTY::ProgressBar.new(
40+
'[:bar] (:percent (:current/:total), rate: :rate/s, mean rate: :mean_rate/s, :elapsed total, ETA: :eta_time)',
41+
bar_format: :box,
42+
advance: num_for_progress_advance(count),
43+
total: count
44+
)
45+
end
46+
47+
def num_for_progress_advance(count)
48+
return 1 if count < 100
49+
50+
count / 100
51+
end
52+
end

0 commit comments

Comments
 (0)