Forum: Ruby on Rails Rails way to do long running tasks

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A55c9166450a21261741dc7750ec3d7e?d=identicon&s=25 Chris (Guest)
on 2009-06-07 09:05
(Received via mailing list)
Hello Rails community,

  I would like to get some advices - I am writing a web application
that will be sending some emails and execute other long running tasks.

  Some of these tasks may take some time and I do not want the user
experience to be impacted. I would appreciate any pointers on advices
on these areas:

   *   how to send emails without making the user wait
   *   how to execute long running tasks
   *   The best way to do periodic cron jobs in Rails

Thank you for your help in advance.

Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-06-07 11:55
(Received via mailing list)
Chris wrote:

>    *   how to send emails without making the user wait

Either{}, or a plugin called Spawn. You need the latter if
e-mails call templates which in turn call ActiveRecord. A separate
requires a separate database connection, and Spawn handles this.

>    *   how to execute long running tasks

The threading option has one flaw: If your web server expunges your
module from memory, the thread lapses.

When sending a few emails, if you can't send them before process
time, you have bigger problems than a missing email. Failing that
analysis, you
need an out-of-process solution like BackgroundRB. It runs in a daemon
of its
own and communicates with your app thru dRB. In exchange for a fatter
and more
fragile implementation, you get a process you can control directly.

>    *   The best way to do periodic cron jobs in Rails

Create a folder called cron, write (using TDD!) a script that does what
need, and install it into your OS's cron system as the command line
script/runner lib/my_script.rb.

If I needed to send e-mails, I would pool them up, then push them out
with a
cron. The previous two options allow communication back to the user in
subsequent controller actions. You probably don't need that, so just
configure a
cron to run every 90 seconds, and send emails for up to 1 minute. Take a
care to not send the same email twice, and you are set.

6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2009-06-07 19:02
(Received via mailing list)
For emails, the simplest way is to set up a local MTA (postfix, for
instance) and send the mail to that. The MTA takes care of the hard
part delivering the mail as needed.

For more general things, there are some gems that let you set up cron-
like tasks, or you can just call a rake task from plain old cron.

--Matt Jones
D3fc5887a2f39f2e0c8989d39ce5e6f9?d=identicon&s=25 Bharat Ruparel (bruparel)
on 2009-06-07 19:56
(Received via mailing list)
Two pointers from personal experience:

1.  Don't use backgroundrb for asynchronous processing
2.  Do use javan-whenever to automate your cron jobs (available on

4ab2692ba129cb296d4f2e90ba5241da?d=identicon&s=25 Sandip Ransing (san2821)
on 2009-06-08 16:36
(Received via mailing list)

Can you give brief why to use javan instead backgroundrb ?
As, i am using backgroundrb for heavy upload duties and it works fine

- Sandip R~

On Sun, Jun 7, 2009 at 11:26 PM, Bharat <> wrote:

Ruby on Rails Developer
A55c9166450a21261741dc7750ec3d7e?d=identicon&s=25 Chris (Guest)
on 2009-06-13 21:37
(Received via mailing list)
Thanks a lot for the pointers and the great suggestions.

I really do find BackgrounDrb too heavy for my implementation - and
think the gems you described make sense.

Spawn plugin and Javan-whenever is great.  And there is a Railscast
that is really good in explaining:
63141c1a664a3f157078d866810935de?d=identicon&s=25 Jiten Bhagat (jits)
on 2009-06-14 00:19
(Received via mailing list)
I would highly recommend using delayed_job ( We've recently
this into the BioCatalogue ( to great
This is what GitHub use I believe

Useful blog post that walks you through setting up delayed_job -

Useful FAQ:



Hope that helps.


2009/6/13 Chris <>
This topic is locked and can not be replied to.