Skip to content

Latest commit

 

History

History
88 lines (62 loc) · 3.49 KB

README.md

File metadata and controls

88 lines (62 loc) · 3.49 KB

SidekiqSendMail

Gem Version Build Status Coverage Status Code Climate Dependency Status

Render mail, serialize it and then send it to a Sidekiq queue for dispatch by a background process.

Why use this?

  • Other gems typically require you to render emails in background processes. This requires you to load the whole Rails stack and your application plus dependencies. This is an alternative approach that reduces overhead by serializing via Mail::Message#to_yaml.

  • One SidekiqSendMail process can serve many applications, you do not need one for each.

  • If you'd like to add fault tolerance and be able to see failures and retry emails, Sidekiq has these features and provides a neat web interface.

If sending mail is the only thing you want to do in the background then this gem is ideal for that purpose.

Requirements

SidekiqSendMail is tested under a wide range of Ruby and Rails configurations. The ActionMailer component is automatically skipped when not relevant so this gem can be used in combination with other frameworks.

Sidekiq requires Redis 2.4+. Sidekiq versions after 3.2.1 no longer support Ruby 1.9.3.

Installation

Add this line to your application's Gemfile:

gem 'sidekiq_send_mail'

Run Bundler to install the gem:

bundle install

Usage

Rails (via ActionMailer Hooks)

Create a new initializer config/initializers/sidekiq_send_mail.rb in your application containing:

ActionMailer::Base.register_interceptor(SidekiqSendMail::MailInterceptor)

Ensure Redis is running and your emails will now be queued via Sidekiq.

To perform this only in production/staging, you can use:

ActionMailer::Base.register_interceptor(SidekiqSendMail::MailInterceptor) if %w(staging production).include?(Rails.env)

Starting Sidekiq

To actually send the emails you've queued, you need to start Sidekiq. An executable is provided with this gem for basic operation, open a terminal and execute:

sk_send_mail

This initiates a barebones Sidekiq process bound to the 'emails' queue with a concurrency of 1 and a shutdown timeout of 20s.

To shut down this process, you use the command:

sidekiqctl shutdown /tmp/sidekiq-emails.pid

See the source or the Sidekiq wiki for more information.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

MIT: http://pg.mit-license.org