Skip to content

Commit

Permalink
Adds a report for version mismatches.
Browse files Browse the repository at this point in the history
refs #5074
  • Loading branch information
justinlittman committed Jun 7, 2024
1 parent 3156cb5 commit 932a744
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions app/reports/preservation_versions.rb
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

0 comments on commit 932a744

Please sign in to comment.