play/type blog

We are creating Germany's juiciest event platform, boomloop.com. Because we love the Internet more than our own mothers. See for yourself. check out boomloop.com


11
Nov

Sending mail asynchronously in Rails using Workling

If you want to send mail asynchronously in your rails app, but don’t want to bother with using a queue server like Starling, then have a go at this…

First, run this:

./script/plugin install git://github.com/purzelrakete/workling.git
./script/plugin install git://github.com/langalex/workling_mailer.git
./script/plugin install git://github.com/matthewrudy/rudeq.git
rake queue:setup
rake db:migrate

now add this to your environment:

Workling::Clients::MemcacheQueueClient.memcache_client_class = RudeQ::Client
Workling::Remote.dispatcher = Workling::Remote::Runners::ClientRunner.new

Finally, add this into the body of your mailer classes:

include AsynchMail

now start the workling client:

./script/workling_client start

done!

Comments

There are 9 Comments for this post.  Write comment →

Do not forget to add

class MyMailer < ActionMailer::Base
include AsynchMail
end

in your mailer class.

Quote from the Readme:
This dynamically creates a workling worker for the mailer. From now on all MyMailer.deliver_whatever_email calls create
an entry in the corresponding queue and should be processed by a worker. If you still want to deliver mail sycnhronously
add a bang to the method call: MyMailer.deliver_whatever_email!

Regards
Sam

@Sam thanks ;) i’ve updated the post.

I tried this, and it works just fine and out-of-the box while in development environment. But when in production environment it somehow just doesn’t do anything. No Log entries about polling the database from the workling_client and no emails going out.

I would love to use this really easy and straightforward solution to async mailing in rails.

Surely you would just use an MTA which is specifically writen to send emails asynchronously. Have a look at postfix.

@filterfish yeah, but you still have to send the content to the mta. this becomes an issue if you’re sending out attachments.

Hello, I met the same problem. EmailerWorker do anything. in the log, I saw there has a sql to insert a record to RudeQueues. but I didn’t see any log about email sent. and it works fine before I add Bj on my project.
and I delete BJ(Backgroundjob), it’s no useful. EmailerWorker doesn’t back…

AnySuggestion for me? thanks.

FYI (to those selling that mail are not sent):

of course you should specify the correct RAILS_ENV, otherwise the workling_client could not find the rude_queue table (or it will find it empty), so start it with:

RAILS_ENV=production ./script/workling_client start

Thx, it works out of the box. It solved a real issue as the notification sending in a social network software website i am doing

Hi there. I know this is not a support forum, but an undefined method `get’ error (http://pastie.org/420580) in my staging server. It’s very clean hardly any gems installed, so it must be a missing gem.

I was wondering – is there a list of things that Workling is dependent on? It barfed when I didn’t have daemons, then it barfed when I didn’t have eventmachine. I guess a list of all gems it needs would be super cool :)

Thanks!

Hi there. I know this is not a support forum, but an undefined method `get’ error (http://pastie.org/420580) in my staging server. It’s very clean hardly any gems installed, so it must be a missing gem.

I was wondering – is there a list of things that Workling is dependent on? It barfed when I didn’t have daemons, then it barfed when I didn’t have eventmachine. I guess a list of all gems it needs would be super cool :)

Thanks!

Write a comment

Required in bold.