Skip to content

Commit

Permalink
[#2552] Don't stop the SCSB import full job if stale file is already …
Browse files Browse the repository at this point in the history
…deleted
  • Loading branch information
sandbergja committed Dec 16, 2024
1 parent 33376f4 commit fd542dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/jobs/scsb_import_full_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ def created_dump(event)
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")
FileUtils.rm Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.csv")
files_to_delete = Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.zip")
.concat(Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.xml"))
.concat(Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.csv"))
files_to_delete.each do |file|
FileUtils.rm file
rescue Errno::ENOENT
Rails.logger.warn("Attempted to delete file #{file}, but it was no longer present on the filesystem")
next
end
end
end
17 changes: 16 additions & 1 deletion spec/jobs/scsb_import_full_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
expect(Scsb::PartnerUpdates).to have_received(:full)
end

describe 'when there stale files in the update directory path' do
describe 'when there are stale files in the update directory path' do
let(:update_directory_path) { Rails.root.join("tmp", "specs", "update_directory") }

before do
Expand All @@ -36,5 +36,20 @@
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

context 'when one file deletion fails' do
before do
allow(FileUtils).to receive(:rm).and_call_original
allow(FileUtils).to receive(:rm).with(Rails.root.join("tmp", "specs", "update_directory", 'NYPL_20210430_015000.zip').to_s).and_raise(Errno::ENOENT, 'No such file or directory @ apply2files')
end
it 'still deletes the other files that have not failed' do
described_class.perform_now

expect(FileUtils).to have_received(:rm).exactly(4).times
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", '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
end
end
end
end

0 comments on commit fd542dc

Please sign in to comment.