Code Monkey home page Code Monkey logo

que-mailer's Introduction

Que-Mailer

Asynchronously send mail using ActionMailer and Que.

So far, this has been tested only in Rails 4.

Que is an alternative DelayedJob or QueueClassic and is a queue for Ruby. It uses PostgreSQL's [advisory locks] (http://www.postgresql.org/docs/current/static/explicit-locking.html#ADVISORY-LOCKS) to manage jobs. See the que repo for more details.

Why Que-Mailer?

  • Que-Mailer uses Postgres rather than Redis, RabbitMQ or other message queue. If you already have Postgres on a project, now you have 1 fewer dependency!
  • Que-Mailer can create background workers within your existing process. This means, for instance, that your background workers and web server can share a Heroku dyno. It also means that you don't have to remember to launch separate workers.
  • All of the benefits of using advisory locks and Postgres (like safety, security, and atomic backups.)

Warning

Que and Que-Mailer are fairly new compared to other queue solutions. We're still finding bugs and have only tested in a limited set of configurations.

If you have problems, please post an issue.

Installation

Right now it is best to use the github master version.

Add this line to your application's Gemfile:

gem 'que_mailer', :git => 'git://github.com/prehnRA/que-mailer.git', :branch => 'master'

And then execute:

$ bundle

Additionally, you need to follow the steps for installing and using Que. Remember to:

$ rails generate que:install
$ rake db:migrate

Which will get your database ready to store jobs.

Use

You use Que-Mailer by including it in your mailers, like this:

class ExampleMailer < ActionMailer::Base
  include Que::Mailer
  default from: '[email protected]'
  
  def example_message(*args)
    @args = *args
    mail(to: "[email protected]", subject: "Hello World")
  end
end

Then,

ExampleMailer.example_message.deliver 

will send mail using the background workers.

ExampleMailer.example_message.deliver!

will bypass Que and send the mail directly.

Scheduling Mail

Additionally, you can schedule mail to be sent at a later time.

ExampleMailer.deliver_in(2.days)

will send an email two days from now.

ExampleMailer.deliver_at(time)

will deliver the email at time.

Contributing

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

You can also help by testing this in your application and reporting any issues you encounter.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.