diff --git a/app/jobs/scsb_import_full_job.rb b/app/jobs/scsb_import_full_job.rb index 00107d88..8630e5e5 100644 --- a/app/jobs/scsb_import_full_job.rb +++ b/app/jobs/scsb_import_full_job.rb @@ -1,6 +1,7 @@ class ScsbImportFullJob < ApplicationJob def perform - FileUtils.rm Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.zip") + delete_stale_files + Event.record do |event| event.dump = created_dump event.save! @@ -18,4 +19,9 @@ def dump_type def created_dump Dump.create!(dump_type:) end + + def delete_stale_files + FileUtils.rm Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.zip") + FileUtils.rm Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.xml") + end end diff --git a/spec/fixtures/scsb_updates/scsb_update_20240108_183400_1.xml b/spec/fixtures/scsb_updates/scsb_update_20240108_183400_1.xml new file mode 100644 index 00000000..461004d2 --- /dev/null +++ b/spec/fixtures/scsb_updates/scsb_update_20240108_183400_1.xml @@ -0,0 +1,6 @@ + + +02152cam a2200493 i 4500SCSB-2170814NNC20240105113043.0810220s1976 txu 000 0beng 39998 76620048 (OCoLC)ocm03111350DLCengDLCOCLOCLCQBAKERBTCTAYDXCPOCLCGNLEHEBISOCLCOOCLCQOCLCFOCLCOFC@OCLCANLCTYCOCLCQOCLUKMGBOCLCQOCLCOOCLNIUGZNOCLCOOCLCL781538947can087959022X9780879590222(OCoLC)3111350PR5366.L38 1976822/.9/1218Bcci1icclaccZCUALaurence, Dan H.Shaw, books, and libraries /Dan H. Laurence.[Austin] :Humanities Research Center, University of Texas at Austin,©1976.28 pages ;23 cmtexttxtrdacontentunmediatednrdamediavolumencrdacarrierBibliographical monograph series ;no. 9"Five hundred copies have been printed on Curtis Rag. The type is Intertype Baskerville. Design by William R. Holman"--Colophon.Shaw, Bernard,1856-1950Books and reading.Dramatists, Irish20th centuryBiography.Dramatists, English20th centuryBiography.Shaw, Bernard,1856-1950fasthttps://id.oclc.org/worldcat/entity/E39PBJfmqrHfjT8qvwDyYWVKVC(OCoLC)fst00030129Dramatists, Englishfast(OCoLC)fst00897581Dramatists, Irishfast(OCoLC)fst008976081900-1999fastAmerican cinema filmsShaw, Bernard1856-1950Biographiesfast(OCoLC)fst01919896Holman, William Roger,designer.Online version:Laurence, Dan H.Shaw, books, and libraries.[Austin] : Humanities Research Center, University of Texas at Austin, ©1976(OCoLC)560755727Bibliographical monograph ;no. 9.PR5366 .L38 19762137624scsbcul21376243304030AvailableCU553988631SharedCURECAP + \ No newline at end of file diff --git a/spec/jobs/scsb_import_full_job_spec.rb b/spec/jobs/scsb_import_full_job_spec.rb index 3aa7ea9f..bcaf3c4a 100644 --- a/spec/jobs/scsb_import_full_job_spec.rb +++ b/spec/jobs/scsb_import_full_job_spec.rb @@ -24,16 +24,17 @@ FileUtils.cp('spec/fixtures/scsb_updates/CUL_20210429_192300.zip', update_directory_path) FileUtils.cp('spec/fixtures/scsb_updates/NYPL_20210430_015000.zip', update_directory_path) FileUtils.cp('spec/fixtures/scsb_updates/HL_20210716_063500.zip', update_directory_path) + FileUtils.cp('spec/fixtures/scsb_updates/scsb_update_20240108_183400_1.xml', update_directory_path) end it 'removes stale files' do - expect { described_class.perform_now }.to change { Event.count }.by(1) - + expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'CUL_20210429_192300.zip'))).to be false expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'NYPL_20210430_015000.zip'))).to be false expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'HL_20210716_063500.zip'))).to be false + expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'scsb_update_20240108_183400_1.xml'))).to be false expect(Dir.exist?(Rails.root.join("tmp", "specs", "update_directory"))).to be true end - end + end end