duck_punching

Ruby, Rails and tech. No ducks were harmed in the making of this blog.

ar_mailer gem forked on GitHub, goodies added

Now that GitHub has a gem server it allows the process of managing your own fork or customisation of a gem ridiculously easy. No need for your own gem server or shipping around gem files, just put it up on github and nominate it as a gem in the project config. GitHub will automatically compile the gems using a gemspec file if present. All the info you need is here so I won’t recap it any further.

A gem which I find essential for Rails apps which send out emails is ar_mailer by Eric Hodel of Seattle Ruby Brigade and Ruby Hitsquad fame and now the maintainer of RubyGems. But there a couple of things missing. One is the need for pid files to be generated when running as a daemon to allow effective management with monitoring tools and such.

Well there just so happened to be a patch by Dylan Egan in the ar_mailer forums to add this feature, but it has been overlooked for a long time. So I thought this would be a good chance to fork it and use the GitHub gem system as well. Its now forked it and patched with some tweaks to get it working and a few fixes for the tests which broke due to changes in the latest ZenTest gem.

The project for the gem is here. To use the new gem you need to remove the old one because of the way github names your gems. It uses github username as a prefix to the gem name. This means the old gem will be loaded instead of the new gem when required in your app. But the binary will be used from the new gem causing nasty problems.

To install, first add GitHub as a gem source

sudo gem sources -a http://gems.github.com

Then

sudo gem install adzap-ar_mailer

Now when the binary is run in daemon mode you will get the pid file you need. You can specify the pid file location in the command options like so

ar_sendmail -d -p ./log/ar_sendmail.pid

Any relative paths are expanded from the app directory. You can of course use an absolute path if you wish. The file gets removed on exit as you would expect.

The other major addition is not as visible. Its a Ruby based init.d script for managing mailer startup for one or more apps. It uses a yaml based config file where you specify the app settings for each app that needs a mailer instance running. See the README and demo config for more info.

Ruby, my hammer, is starting to make everything look a nail!

Remember this is GitHub, don’t like what I have done, then fork off!

UPDATE:
If you are getting an error running the ar_sendmail binary, this is due to GitHub to setting the permission on gem binary files incorrectly. The error would be

/usr/bin/ar_sendmail:19:in `load': no such file to load -- ar_sendmail (LoadError)
	from /usr/bin/ar_sendmail:19

To fix it you need to run this ugly (please let me know a better way to get a gem path!!)

GEMS_PATH=`gem env path`
GEM_NAME='adzap-ar_mailer'
sudo chmod 755 $GEMS_PATH/gems/$GEM_NAME*/bin/*

Now you should be able to execute it as a normal user.

UPDATE 2:
Fixed the update fix and made it version non-specific

UPDATE 3:
GitHub fixed the file permissions issue so the work around is not needed anymore.

2 comments

2 Comments so far

  1. Georges October 2nd, 2009 1:32 am

    My company has wrestled with ar_mailer in the past and it has mostly satisfied our needs, but we figured there had to be a better way.
    Mass mailing in rails has always been a pain in the ass, so why not cut it out of the app and have a dedicated process for it?

    We took a stab at making this kind of solution, take a look: http://blog.twg.ca/2009/09/rails-mass-mailing-it-shouldnt-be-this-complicated

    Would love to get your feedback on the idea.

  2. minigamez August 18th, 2011 9:59 pm

    Excellent site, keep up the good work my colleagues would love this.

Leave a reply

Mexico