Efficient way of organizaing mail sending from Rails app

104 views Asked by At

I have an Rails 4 application with ruby 2.1.2 that runs on a VPS with 512 mb of RAM and want to know what are the ways of efficiently managing email notification with background job with the least possible additional background processes ( like Redis and Sidekiq, each of them needs to be run as a demon in the backend ).

I've read about queue_classic gem that uses same Postgres DB that is already there and adds only one more additional process that manages the queue.

I have a system that sends updates for changes in the records to relevant users. This is a scout merit badge system. In the first phase users will generate a lot of new records and lots of updates. But after some time the changes will be not so big, thus no much e-mails. I assume that there can be up to 1000 emails daily during first week and 500 e-mails weekly afterwards.

So what are options of having either a simple background job managing system ( like queue_classic - it requires ruby 1.9.2, so I'm not lucky ) or some service that can for free send the letters (acting to the application in the same non-blocking manner as bg manager) with the least footprint on the RAM usage?

1

There are 1 answers

0
aratak On BEST ANSWER

sucher_punch and Mandrill (or any other similar) service could work in a good tandem. sucher_punch don't need separate process and could work from the box and Mandrill service works outside from the application, thus it doesn't require additional memory or installation.

You need to create separate job which delivers email

class EmailJob
  include SuckerPunch::Job

  def perform(user_id)
    @user = User.find(user_id)
    ::Notifications.some_notification_to(@user).deliver
  end
end

Call it from the code:

EmailJob.new.async.perform(user.id)

Don't forget to configure the mandrill inside production.rb:

config.action_mailer.default_url_options = { :host => 'example.com' }
config.action_mailer.smtp_settings = {
  address: 'smtp.mandrillapp.com',
  port: SOMEPORT,
  domain: 'example.com',
  authentication: :plain,
  enable_starttls_auto: false,
  user_name: SOMEUSERNAME,
  password: SOMEPASSWORD
}