Coder Social home page Coder Social logo

mongo_mailer's Introduction

MongoMailer

Gem Version Build status Code Climate Coverage Status

Asynchronous mail delivery with mongodb for Rails

Elements

  • Rails plugin containing delivery_method, generators, capistrano recipies
  • worker daemon fetching mails for queue and doing the final delivery using two methods: base and emergency, if base delivery fails, then emergency is being used.

Rails plugin

Add mongo_mailer to your Gemfile:

gem 'mongo_mailer', require: 'mongo_mailer/rails'

Run the generator:

bundle exec rails generate mongo_mailer

which creates config/mongo_mailer.yml.example

Based on example configuration file, create mongo_mailer.yml and add it to gitignored. mongo_mailer.yml contains configuration of mongo database and final delivery methods used by worker.

Set ActionMailer::Base delivery method in your environment file:

config.action_mailer.delivery_method :mongo_queue

Add mongo_mailer capistrano recipies, by adding:

require 'mongo_mailer/capistrano'

to your deploy.rb. Since then you have access to cap mongo_mailer:start|stop|restart recipies.

Standalone worker

Worker can be used within a rails app or as a standalone application. In both cases only mongo_mailer related stuff is used - rails are never being loaded.

Worker usees daemons to daemonize the process, continuously polls mongo queue for new mail and does the final delivery.

  • to start, stop or restart worker just run:
bundle exec mongo_mailer start|stop|restart [rails_env]

within a rails app, or:

bundle exec worker start|stop|restart [app_env]

in a standalone version.

  • by default workers activity and pids are being loged in the app's log directory:
log/mongo_mailer.output
log/mongo_mailer.log
log/mongo_mailer.pid

you can change it, by modifying proper daemon options in mongo_mailer.yml.

  • all sent mail are logged into:
log/mongo_queue.log

Debugging & stats

mongo_mailer doesn't have any web interface, so irb console is the only interface to get information :)

Getting number of sent messages for each delivery method:

MongoMailer::DeliveriesCounter.instance.by_type(:base)
=> {"_id"=>BSON::ObjectId('5177ecb0df30cc350e3fbdf3'), "type"=>:base, "value"=>11}

MongoMailer::DeliveriesCounter.instance.by_type(:emergency)
=> {"_id"=>BSON::ObjectId('5178f501df30cc350e3fbdf4'), "type"=>:base, "value"=>1}

MongoMailer::DeliveriesCounter.instance.all
=> [{"_id"=>BSON::ObjectId('5177ecb0df30cc350e3fbdf3'), "type"=>:base, "value"=>11}, {"_id"=>BSON::ObjectId('5178f501df30cc350e3fbdf4'), "type"=>:emergency, "value"=>1}]

Getting list of unsent message due to errors:

MongoMailer::MailQueue.instance.invalid_items

Clearing the list of unsent messages:

MongoMailer::MailQueue.instance.clear_invalid_items!

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

mongo_mailer's People

Contributors

knapo avatar radwo avatar

Stargazers

RocknrollMarc avatar

Watchers

James Cloos avatar RocknrollMarc avatar

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.