Search code examples
ruby-on-railsherokusidekiqmailgun

Sidekiq: Pass email body and attachments for processing?


I just learned/started using Sidekiq today to handle background processing of incoming email messages and attachments, but am a bit lost on the best way to get the email body and attachments into the worker for processing.

My RoR app is hosted on Heroku and receives incoming emails via Mailgun to a controller, which then kicks off my worker. Within the worker is a call to a 3rd party API to upload my email messages and attachments (think DropBox.)

Mailgun pre-parses everything and sends it over as parameters, but from what I understand about Sidekiq, I don't want to pass along entire objects such as the email body and/or attachments as shown here.

@attach_count = params["attachment-count"]
@from = params["from"]
@subject = params["subject"]
@msgbody = params["body-html"]
ProcessEmailWorker.perform_async(@id, @attach_count, @from, @subject, @msgbody) 

What's the best practice for getting these items over to my worker?


Solution

  • After speaking with another developer I chose to do the following:

    1. Set up a route in Mailgun to store the incoming email message, but to post a notification to my controller

    2. Have my controller grab the incoming message ID and pass that along to my worker

    3. From within my worker, use the message ID to perform a GET to Mailgun to retrieve the stored message (and its attachments)

    4. Process the message/attachments and upload them to my cloud storage provider.