emory-libraries/dlp-selfdeposit

View on GitHub
app/jobs/fileset_clean_up_job.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

class FilesetCleanUpJob < Hyrax::ApplicationJob
  def perform(*file_set_ids)
    csv_path = Rails.root.join('tmp', 'emory', 'index_file_set_results.csv')
    ::FileUtils.mkdir_p(File.dirname(csv_path))
    CSV.open(csv_path, "w") do |csv|
      if file_set_ids.present?
        file_set_ids.flatten.each do |id|
          file_set = ::Hyrax.query_service.find_by(id:)
          process_fileset(file_set, csv)
        end
      else
        ::Hyrax.query_service.find_all_of_model(model: ::FileSet).each do |file_set|
          process_fileset(file_set, csv)
        end
      end
    end
  end

  private

  def process_fileset(file_set, csv)
    characterize_file_set(file_set, csv)
  end

  def characterize_file_set(file_set, csv)
    ::ValkyrieCharacterizationJob.perform_later(file_set.original_file_id.to_s)
    csv << [file_set.id, "Fileset not characterized", "Queued"]
  end
end