views:

1898

answers:

8

What is the preferred way to create a background task for a Rails application? I've heard of Starling/Workling and the good ol' script/runner, but I am curious which is becoming the defacto way to manage this need?

Thanks!

Clarification: I like the idea of Rake in Background, but the problem is, I need something that is running constantly or every 10 hours. I am not going to have the luxury of sitting on a web request, it will need to be started by the server asynchronous to the activities occurring on my site.

A: 

I have used the daemons plugin in the past.

frankodwyer
+13  A: 

Ryan Bates created three great screencasts that might really help you:

  1. Rake in Background
  2. Starling and Workling
  3. Custom Daemon

He talks about the various pros and cons for using each one. This should help you get started.

Tim K.
+1 For starling.Currently using it in production. It's fast enough, reliable, and has a code base so small you can easily understand it all in a few minutes.
Michael
A: 

While I don't know if it is becoming a standard, I have had great success with BackgroundRB. I have several workers, some are long running tasks triggered by a user action while others are started on a schedule.

salt.racer
A: 

async_observer is the best. It doesn't do all kinds of dumb busy wait stuff or lose jobs on worker crashes like starling, no DB polling, etc... and it integrates into rails remarkably well.

I push tons of jobs through it and it pretty much doesn't care.

Dustin
+3  A: 

It depends on your needs.

Try out delayed_job, which is maintained by Tobi, a Shopify founder, and forked by DHH.

maurycy
+2  A: 

I usually rely on cronjob scheduling as it gives the flexibility without having to write separate code to schedule it. Anything that can be executed from shell, can be scheduled! Be it any script (ruby / rake task / py / bash / any other you like), cronjob scheduling can be easily achieved.

If running on windows, one can use scheduled tasks

Hope this helps.

Chirantan
+1  A: 

Most of the plugins that have been mentioned will do the job, but if all you need is a Rake task run on a set schedule, then there's really no need to start throwing more architecture at it.

Just add a cron job which executes

"cd /path/to/rails/app; RAILS_ENV=production rake run:my:task"

Why reinvent the wheel, when Unix like operating systems have been running tasks on a schedule for decades?

Jon Wood
A: 

Have a look at Taskr. It's basically like cron, but with a RESTful web interface. You can use it to schedule tasks to periodically connect to your Rails app and trigger arbitrary code (via the Taskr4rails plugin). It's meant to fit nicely into a system built around RESTful services, plus it can notify you if a task returns an error, fails to run, etc.