Skip to content

Commit

Permalink
use timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed Jan 29, 2024
1 parent 46c55b8 commit 14bb271
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions app/lib/email_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,16 @@ def collage_from_mailgun_attachments
return unless last_message.present?

message = nil
5.times do
message_url = URI.parse(last_message["storage"]["url"])
msg_conn = Faraday.new("https://#{message_url.host}") do |f|
f.options[:timeout] = 29
f.request :json
f.response :json
f.request :authorization, :basic, 'api', ENV['MAILGUN_API_KEY']
end
response = msg_conn.get(message_url.path)
message = response.body if response.success?
break if message.present?
sleep 10
message_url = URI.parse(last_message["storage"]["url"])
msg_conn = Faraday.new("https://#{message_url.host}") do |f|
f.options.timeout = 20
f.options.open_timeout = 20
f.request :json
f.response :json
f.request :authorization, :basic, 'api', ENV['MAILGUN_API_KEY']
end
response = msg_conn.get(message_url.path)
message = response.body if response.success?
return unless message.present? && message["recipients"].to_s.include?(@user.user_key) || message["from"].to_s.include?(@user.email)

attachment_urls = message["attachments"].map do |att|
Expand Down

0 comments on commit 14bb271

Please sign in to comment.