# Simultaneous long-running tasks; Rake, Daemons, Delayed::Jobs?

**URL:** <https://www.ruby-forum.com/t/simultaneous-long-running-tasks-rake-daemons-delayed-jobs/178406>\
**Category:** Rails\
**Created:** [November 4, 2009, 2:53am UTC](https://www.ruby-forum.com/t/simultaneous-long-running-tasks-rake-daemons-delayed-jobs/178406 "2009-11-04T02:53:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_von\_Conra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sebastian\_von\_Conra](https://www.ruby-forum.com/u/Sebastian_von_Conra)\
**Post date:** [November 4, 2009, 2:53am UTC](https://www.ruby-forum.com/t/simultaneous-long-running-tasks-rake-daemons-delayed-jobs/178406/1 "2009-11-04T02:53:47Z")

</div>

Hi everyone,

I have an application where an essential part is communicating with a  
remote API via SOAP. I want to be able to run 3-4 of these tasks at  
once, and one task might take anything from one minute to several  
hours, depending on the size of the data being sent. The app relies  
heavily on ActiveRecord fetching fetching data (in\_batches) and  
updating it once the response from the API has been received.

I’m using Ruby 1.8.6 and Rails 2.3.4.

In an earlier version of this application (written in PHP), this was  
set up as a cron job which called the relevant scripts via curl. This  
was obviously not the best implementation, and so it was decided to  
move to Rails.

After having done quite a bit of research, I can’t for the life of me  
figure out what the best approach to handle these long-running tasks  
would be. Initially I was going to set them up as Rake tasks, and call  
them with cron every minute. I had a database table with active tasks  
and would only start the task if less than 4 tasks were already  
running.

Then I discovered Daemons, and was trying to figure out if that would  
be a better approach to my issue. And then, I discovered  
Delayed::Jobs, which also could be helpful.

Naturally, I want to perform these tasks as efficiently as possible,  
with the least amount of resources. The tasks will be more-or-less  
around the clock, so I would probably rather have it run continually  
(like a Daemon) than having to reload the libraries every time (which  
I would have to do with Rake). On the other hand, I’m not sure how a  
Daemon would handle concurrent tasks–threading, possibly?

With all of the different options out there, I’m getting more and more  
confused by the minute. Help, anyone?

Best regards,  
Sebastian

---

<div class="post-metadata">

**Author:** ![Sebastian\_von\_Conra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sebastian\_von\_Conra](https://www.ruby-forum.com/u/Sebastian_von_Conra)\
**Post date:** [November 4, 2009, 5:43pm UTC](https://www.ruby-forum.com/t/simultaneous-long-running-tasks-rake-daemons-delayed-jobs/178406/2 "2009-11-04T17:43:03Z")

</div>

I’m using delayed\_job and am happy with the ease of use.  
I haven’t had the need to run more than 1 queued job at a time, but  
you can start any number of workers using the following syntax:

# This would allow up to four simultaneous jobs

$ RAILS\_ENV=production script/delayed\_job -n 4 start

On Nov 3, 5:52 pm, Sebastian von Conrad

---

<div class="post-metadata">

**Author:** ![Sebastian\_von\_Conra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sebastian\_von\_Conra](https://www.ruby-forum.com/u/Sebastian_von_Conra)\
**Post date:** [November 5, 2009, 1:17am UTC](https://www.ruby-forum.com/t/simultaneous-long-running-tasks-rake-daemons-delayed-jobs/178406/3 "2009-11-05T01:17:50Z")

</div>

Thank you for your reply.

I do like the look of Delayed::Job, and after seeing your reply I  
discovered that I must have glossed over something important: That you  
can set up multiple workers on one computer.

I also noticed that you can use Delayed::Job together with a Daemon:  
[http://wiki.github.com/tobi/delayed\_job/running-delayedworker-as-a-daemon](http://wiki.github.com/tobi/delayed_job/running-delayedworker-as-a-daemon)

Does anyone have experience with this setup? If so, how is it working  
for you?

Best regards,  
Sebastian
