# Background tasks that need to start right away

**URL:** <https://www.ruby-forum.com/t/background-tasks-that-need-to-start-right-away/148576>\
**Category:** Rails\
**Created:** [September 15, 2008, 9:13am UTC](https://www.ruby-forum.com/t/background-tasks-that-need-to-start-right-away/148576 "2008-09-15T09:13:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbee-robert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@newbee-robert](https://www.ruby-forum.com/u/newbee-robert)\
**Post date:** [September 15, 2008, 9:13am UTC](https://www.ruby-forum.com/t/background-tasks-that-need-to-start-right-away/148576/1 "2008-09-15T09:13:33Z")

</div>

I’m looking for recommendations for a simple, stable way to accomplish  
this.

Here’s the scenario:

- whenever a user visits my app, I need to fire off a method that  
launches some API calls.
- the user sees a ‘loading’ screen until the method returns some 15-20  
seconds later.

I’ve installed BackgrounDRB and am running it with thread pooling. This  
works, but the job server crashes after a little while (I don’t know how  
many concurrent threads each worker is supposed to handle…)

I’m looking for a solution that’s as simple, lightweight and stable as  
possible for what I need to do. Ideally it wouldn’t involve monitoring a  
separate process.

Right now I’m debating between:

- trying to fix BackgrounDRb
- installing Backgroundjob, which is self-spawning and hopefully more  
reliable
- using spawn, either with forking or threading

What kind of setup would you run?

---

<div class="post-metadata">

**Author:** ![newbee-robert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@newbee-robert](https://www.ruby-forum.com/u/newbee-robert)\
**Post date:** [September 15, 2008, 8:51pm UTC](https://www.ruby-forum.com/t/background-tasks-that-need-to-start-right-away/148576/2 "2008-09-15T20:51:09Z")

</div>

Robert M. wrote:

> Right now I’m debating between:
> 
> - trying to fix BackgrounDRb
> - installing Backgroundjob, which is self-spawning and hopefully more  
> reliable
> - using spawn, either with forking or threading

Well, it appears none of my alternatives would even work…

- Spawn with forking doesn’t seem to work under Passenger
- Spawn with threading doesn’t either (apparently need another Apache or  
something?)
- Backgroundjob doesn’t seem to have any provisions for running  
concurrent tasks…

Any ideas? ☹

---

<div class="post-metadata">

**Author:** ![newbee-robert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@newbee-robert](https://www.ruby-forum.com/u/newbee-robert)\
**Post date:** [October 14, 2008, 4:09pm UTC](https://www.ruby-forum.com/t/background-tasks-that-need-to-start-right-away/148576/3 "2008-10-14T16:09:29Z")

</div>

On Oct 14, 2:07 pm, swachian [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have such a problem as well. Spawn forks well in mongrel, but fails  
> in passenger.  
> However, it can be run spawn in thread mode if you have set the  
> config.active\_record.allow\_concurrency=true .

Something “stupid” like system(“…”) might work (because that’s both  
forking and execing)

Fred

---

<div class="post-metadata">

**Author:** ![newbee-robert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@newbee-robert](https://www.ruby-forum.com/u/newbee-robert)\
**Post date:** [October 14, 2008, 3:08pm UTC](https://www.ruby-forum.com/t/background-tasks-that-need-to-start-right-away/148576/4 "2008-10-14T15:08:17Z")

</div>

I have such a problem as well. Spawn forks well in mongrel, but fails  
in passenger.  
However, it can be run spawn in thread mode if you have set the  
config.active\_record.allow\_concurrency=true .

On Sep 16, 2:51 am, Robert M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![newbee-robert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@newbee-robert](https://www.ruby-forum.com/u/newbee-robert)\
**Post date:** [October 14, 2008, 4:56pm UTC](https://www.ruby-forum.com/t/background-tasks-that-need-to-start-right-away/148576/5 "2008-10-14T16:56:27Z")

</div>

the active\_record connection seems to be broken if only use normal  
fork

On Oct 14, 10:08 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
