Skip to content

Commit 44e0e3f

Browse files
author
David Zuckerman
committed
Sending message instead of raising error if lbnl file is not found
1 parent fd5e7bc commit 44e0e3f

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

lib/berkeley_library/sftp_handler/downloader/lbnl.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ def download!(filename: nil, local_dir: '/opt/app/data')
1515
filename ||= default_filename
1616
remote_path = Pathname.new(filename)
1717
local_path = Pathname.new(local_dir) + filename
18-
assert_file_not_processed! local_path
19-
assert_not_exists! local_path
18+
19+
# If the file was already grabbed or process we don't want to retrieve it again
20+
return puts "#{local_path} was already grabbed or processed" if file_retrieved?(local_path)
2021

2122
connect do |sftp|
2223
sftp.download!(remote_path.to_s, local_path.to_s)
@@ -25,9 +26,8 @@ def download!(filename: nil, local_dir: '/opt/app/data')
2526
end
2627
end
2728

28-
def assert_file_not_processed!(filepath)
29-
raise "File was already processed: #{filepath}" \
30-
if Pathname.glob("#{filepath}*.old").any?
29+
def file_retrieved?(filepath)
30+
Pathname.glob("#{filepath}*.old").any? || Pathname.new(filepath).exist?
3131
end
3232

3333
def default_host

spec/downloader/lbnl_spec.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'spec_helper'
44
require 'tempfile'
55

6+
# rubocop:disable Metrics/BlockLength
67
describe BerkeleyLibrary::SftpHandler::Downloader::Lbnl do
78
its(:default_host) { is_expected.to eq 'ncc-1701.lbl.gov' }
89
its(:default_username) { is_expected.to eq 'ucblib' }
@@ -25,15 +26,15 @@
2526
Timecop.unfreeze
2627
end
2728

28-
it "downloads this week's file" do
29+
it 'downloads this week\'s file' do
2930
expect(sftp_session)
3031
.to receive(:download!)
3132
.with(todays_remote_path.to_s, Pathname.new("/opt/app/data/#{this_weeks_filename}").to_s)
3233

3334
subject.download!
3435
end
3536

36-
it "downloads to an alternate local_dir" do
37+
it 'downloads to an alternate local_dir' do
3738
local_dir = '/netapp/alma/lbnl_patrons'
3839

3940
expect(sftp_session)
@@ -43,7 +44,7 @@
4344
subject.download!(local_dir: local_dir)
4445
end
4546

46-
it "downloads a specific file" do
47+
it 'downloads a specific file' do
4748
filename = 'lbnl_people_20220516.zip'
4849
remote_path = Pathname.new(filename)
4950
local_path = Pathname.new("/opt/app/data/#{filename}")
@@ -56,14 +57,19 @@
5657
end
5758
end
5859

59-
describe '#assert_file_not_processed!' do
60-
it 'proceeds if processed file is absent' do
61-
expect { subject.assert_file_not_processed!('/path/to/non-existent-file') }.not_to raise_error
60+
describe '#file_retrieved?' do
61+
it 'returns false if file was already retrieved or processed' do
62+
expect(subject.file_retrieved?('/path/to/non-existent-file')).to be(false)
6263
end
6364

64-
it 'raises if processed file exists' do
65-
f = Tempfile.new(['temp_file38348', '.old'])
66-
expect { subject.assert_file_not_processed! f.path.gsub('.old', '') }.to raise_error RuntimeError
65+
it 'returns true if file was already retrieved' do
66+
f = Tempfile.new('temp_file38348')
67+
expect(subject.file_retrieved?(f)).to be(true)
68+
end
69+
70+
it 'returns true if file was already processed' do
71+
f = Tempfile.new('temp_file38348.old')
72+
expect(subject.file_retrieved?(f)).to be(true)
6773
end
6874
end
6975

@@ -101,3 +107,4 @@
101107
end
102108
end
103109
end
110+
# rubocop:enable Metrics/BlockLength

0 commit comments

Comments
 (0)