I'm new to designing scalable RoR apps, so I'm hoping for suggestions on how to reconfigure/rearchitect the following. I have a RoR app hosted on Heroku that receives incoming emails via Mailgun to a controller, which then parses the email and uploads them for storage.
I'm getting H12-Request Timeout errors in my Heroku logs when attempting to process emails with multiple/large attachments. The timeout is reported back to Mailgun, which then attempts to retry the request at predefined intervals, meanwhile Heroku continues to process the request...so it gets caught in a loop and I wind up with multiple uploads of the same files into storage.
Within Heroku I have 1 web and 1 work dyno, running Puma as my web server.
Here is my puma.rb file:
preload_app!
min_threads = Integer(ENV['MIN_THREADS'] || 0)
max_threads = Integer(ENV['MAX_THREADS'] || 5)
threads min_threads, max_threads
workers Integer(ENV['WORKER_COUNT'] || 3 )
on_worker_boot do
ActiveSupport.on_load(:active_record) do
if Rails.application.config.database_configuration
config = Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
config['pool'] = ENV['DB_POOL'] || 5
ActiveRecord::Base.establish_connection(config)
end
# ActiveRecord::Base.establish_connection
end
end
I'm unclear on how best to take advantage of worker dynos in this situation, and how to report back to Mailgun that all is well so that it doesn't keep attempting the same request.
Please let me know if you need additional information.
Thanks for your time and assistance.
EDIT Some additional information:
My controller is doing all of the processing. I query the database to match the incoming email to a user. Additionally, I am requesting/sending data to a 3rd party API...this is for obtaining a valid authentication token and uploading data.