Skip to content

Commit 0e258da

Browse files
committed
Having no S3 object is not an irregular
1 parent 82cc726 commit 0e258da

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

app/models/message.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ def from_mail(mail, list, list_seq)
9292

9393
class << self
9494
def from_s3(list, list_seq, s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
95-
obj = s3_client.get_object(bucket: BLADE_BUCKET_NAME, key: "#{list.name}/#{list_seq}")
95+
begin
96+
obj = s3_client.get_object(bucket: BLADE_BUCKET_NAME, key: "#{list.name}/#{list_seq}")
97+
rescue Aws::S3::Errors::NoSuchKey
98+
p "#{list.name}:#{seq} doesn't exist in S3"
99+
return
100+
end
96101
str = obj.body.read.force_encoding(Encoding::BINARY)
97102
if str.blank?
98103
p "#{list.name}:#{list_seq} is empty"

bin/import_mails

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ Message.transaction do
4242
message.save!
4343
rescue ActiveRecord::RecordNotUnique
4444
STDERR.puts("#{list.name}:#{seq} already exists in Postgres")
45-
rescue Aws::S3::Errors::NoSuchKey
46-
STDERR.puts("#{list.name}:#{seq} doesn't exist in S3")
4745
rescue StandardError => e
4846
errors << [seq, e]
4947
STDERR.puts("failed to import #{list.name}:#{seq}: #{e}")

0 commit comments

Comments
 (0)