-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a report for version mismatches.
refs #5074
- Loading branch information
1 parent
3156cb5
commit 932a744
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
# Compare SDR versions against Preservation versions | ||
# https://github.com/sul-dlss/dor-services-app/issues/5074 | ||
# Invoke via: | ||
# bin/rails r -e production "PreservationVersions.report" | ||
class PreservationVersions | ||
def self.report | ||
new.report | ||
end | ||
|
||
def report | ||
data = RepositoryObject.joins(:head_version).pluck(:external_identifier, :version) | ||
|
||
progress_bar = tty_progress_bar(data.length) | ||
progress_bar.start | ||
|
||
results = Parallel.map(data.each_slice(10000), | ||
in_processes: 4, | ||
finish: ->(finish_data, _, _) { progress_bar.advance(finish_data.length) }) do |data_slice| | ||
data_slice.map do |druid, version| | ||
begin | ||
preservation_version = Preservation::Client.objects.current_version(druid) | ||
rescue Preservation::Client::NotFoundError | ||
preservation_version = nil | ||
end | ||
preservation_version == version ? nil : [druid, version, preservation_version] | ||
end | ||
end.flatten(1).compact | ||
|
||
CSV.open('preservation_versions_report.csv', 'w') do |csv| | ||
csv << %w[druid version preservation_version] | ||
results.each { |result| csv << result } | ||
end | ||
end | ||
|
||
def tty_progress_bar(count) | ||
TTY::ProgressBar.new( | ||
'[:bar] (:percent (:current/:total), rate: :rate/s, mean rate: :mean_rate/s, :elapsed total, ETA: :eta_time)', | ||
bar_format: :box, | ||
advance: num_for_progress_advance(count), | ||
total: count | ||
) | ||
end | ||
|
||
def num_for_progress_advance(count) | ||
return 1 if count < 100 | ||
|
||
count / 100 | ||
end | ||
end |