Skip to content

Commit

Permalink
change interface for index_alma
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Jun 3, 2024
1 parent c982996 commit db6924e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
10 changes: 4 additions & 6 deletions umich_catalog_indexing/lib/index_alma_for_date.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
$:.unshift "#{File.dirname(__FILE__)}"
require "logger"
require "date"
require "sidekiq_jobs"
require "jobs"

class IndexAlmaForDate
def initialize(alma_files:, date:, solr_url:,
def initialize(file_paths:, date:, solr_url:,
delete_it: DeleteIt.new,
index_it: IndexIt.new)
@date = DateTime.parse(date) # must be a string in the form YYYYMMDD

begin
@alma_files = alma_files.select { |x| x.match?(date_string(@date)) } # must be an array of file paths
@file_paths = file_paths.select { |x| x.match?(date_string(@date)) } # must be an array of file paths
rescue NoMethodError
raise StandardError, "alma_files must be an array of file path strings"
raise StandardError, "file_paths must be an array of file path strings"
end

@solr_url = solr_url
Expand All @@ -39,7 +37,7 @@ def run
private

def files_that_match(pattern)
@alma_files.select { |x| x.match?(pattern) }
@file_paths.select { |x| x.match?(pattern) }
end

def date_string(date)
Expand Down
18 changes: 9 additions & 9 deletions umich_catalog_indexing/spec/index_alma_for_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
before(:each) do
@params = {
date: "20220101",
alma_files: [
file_paths: [
"/some_directory/file1_20220101_delete.tar.gz",
"/some_directory/file2_20220101_delete_1.tar.gz",
"/some_directory/file3_20220101_delete_15.tar.gz",
Expand All @@ -29,8 +29,8 @@
expect { subject }.to raise_error(ArgumentError, "invalid date")
end
it "raises an error when alma files are not an array of strings" do
@params[:alma_files] = "not an array of strings"
expect { subject }.to raise_error(StandardError, "alma_files must be an array of file path strings")
@params[:file_paths] = "not an array of strings"
expect { subject }.to raise_error(StandardError, "file_paths must be an array of file path strings")
end
it "raises an error if solr_url is not a string" do
@params[:solr_url] = []
Expand All @@ -51,16 +51,16 @@
subject.run
end
it "does not call IndexIt when no new files" do
@params[:alma_files][3] = "not_new_anymore"
@params[:alma_files][4] = "not_new_anymore"
@params[:alma_files][5] = "not_new_anymore"
@params[:file_paths][3] = "not_new_anymore"
@params[:file_paths][4] = "not_new_anymore"
@params[:file_paths][5] = "not_new_anymore"
expect(@params[:index_it]).not_to receive(:perform)
subject.run
end
it "does not call DeleteIt when no new files" do
@params[:alma_files][0] = "not_delete_anymore"
@params[:alma_files][1] = "not_delete_anymore"
@params[:alma_files][2] = "not_delete_anymore"
@params[:file_paths][0] = "not_delete_anymore"
@params[:file_paths][1] = "not_delete_anymore"
@params[:file_paths][2] = "not_delete_anymore"
expect(@params[:delete_it]).not_to receive(:perform)
subject.run
end
Expand Down

0 comments on commit db6924e

Please sign in to comment.