# Long Running Tasks - What Pattern?

**URL:** <https://www.ruby-forum.com/t/long-running-tasks-what-pattern/90420>\
**Category:** Rails\
**Created:** [March 28, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/long-running-tasks-what-pattern/90420 "2007-03-28T17:21:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 28, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/long-running-tasks-what-pattern/90420/1 "2007-03-28T17:21:20Z")

</div>

Hi,

I have some tasks that a user initiates from a page. This task might run  
longer than the browser timeout.

What is the best way to deal with this?

Thanks  
Joerg

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 28, 2007, 5:32pm UTC](https://www.ruby-forum.com/t/long-running-tasks-what-pattern/90420/2 "2007-03-28T17:32:22Z")

</div>

Have you looked into the daemons gem? It might possibly fit your need.

RSL

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 28, 2007, 5:38pm UTC](https://www.ruby-forum.com/t/long-running-tasks-what-pattern/90420/3 "2007-03-28T17:38:09Z")

</div>

Thanks - that looks pretty wikkid.

So - what would be a good pattern then?  
I post the request to run the task, on the server start the task in a  
new thread, and tell the user that the task is being performed.

What would be a good practice to inform the user? Send an email? Have  
some or other hook to display it on the site again once the task is  
completed?

Looks promising so far, though.

Joerg

Shawn Roske wrote:

> [http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 28, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/long-running-tasks-what-pattern/90420/4 "2007-03-28T17:52:23Z")

</div>

It depends on what kind of task you are planning on offloading. If it  
is something the user needs to wait for, perhaps you could provide a  
progress bar? Otherwise a system message or email when completed  
should work. Again it depends on what this process is doing and  
whether it “makes sense”.

-Shawn

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 28, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/long-running-tasks-what-pattern/90420/5 "2007-03-28T17:33:22Z")

</div>

[http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 29, 2007, 12:20pm UTC](https://www.ruby-forum.com/t/long-running-tasks-what-pattern/90420/6 "2007-03-29T12:20:04Z")

</div>

Hey Shawn (and Russell and dysinger) thanks for your help so far. I  
didn’t realize that I could use a progress bar for this kind of work.  
Actually not really sure how they work - do they poll the server every  
few seconds?  
Can I use a progress bar with Mongrel? Are there plugins/AJAX widgets  
for progress bars that would be recommended for long running tasks (in  
conjunction with bDRb)?

Thanks so much!

Joerg

Shawn Roske wrote:

> It depends on what kind of task you are planning on offloading. If it  
> is something the user needs to wait for, perhaps you could provide a  
> progress bar? Otherwise a system message or email when completed  
> should work. Again it depends on what this process is doing and  
> whether it “makes sense”.
> 
> -Shawn

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 28, 2007, 10:58pm UTC](https://www.ruby-forum.com/t/long-running-tasks-what-pattern/90420/7 "2007-03-28T22:58:36Z")

</div>

Use DRb or Reliable Messaging to communicate with another back-ground  
process.

On Mar 28, 5:21 am, Joerg D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
