# background process

**URL:** <https://discuss.rubyonrails.org/t/background-process/39697>\
**Category:** rubyonrails-talk\
**Created:** [February 23, 2009, 11:14am UTC](https://discuss.rubyonrails.org/t/background-process/39697 "2009-02-23T11:14:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [February 23, 2009, 11:14am UTC](https://discuss.rubyonrails.org/t/background-process/39697/1 "2009-02-23T11:14:07Z")

</div>

> Hi all
> 
> I am working on a heavy engineering project. And the requirement is  
> that I needto do a lot of process before I store the data to the db.
> 
> Now the question is that I want to do the process that I am doing  
> but I want to do it in the background. What I actually mean to say is  
> that..I just want the user to get a msg that Records Saved. But in real I want the process to go on in background.
> 
> There r multiple callbacks used in my system. Also I dont want to use Starling or workling. pls suggest something where in my requirement is satisfied. Since i dont want the user to wait until my process is  
> going on.

Well one of the other background processors (bj, backgroundrb etc. )  
might do the job

Fred

---

<div class="post-metadata">

**Author:** ![Harm1](https://avatars.discourse-cdn.com/v4/letter/h/e8c25b/32.png) [@Harm1](https://discuss.rubyonrails.org/u/Harm1)\
**Post date:** [February 23, 2009, 11:27am UTC](https://discuss.rubyonrails.org/t/background-process/39697/2 "2009-02-23T11:27:15Z")

</div>

Spawn is dead easy ([http://rubyforge.org/projects/spawn/](http://rubyforge.org/projects/spawn/)). I used it to great effect for sending emails while making the user think they where all already sent. The others Frederick suggested work but are more trouble than starling/workling.

Harm

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [February 23, 2009, 11:48am UTC](https://discuss.rubyonrails.org/t/background-process/39697/3 "2009-02-23T11:48:36Z")

</div>

The way you do that reliably is to spawn another process to handle it. You can do your thing in a thread but that pretty much requires that you're using a thread safe version of rails and has limitations given ruby's threading (eg your thread can block the whole mongrel)

Fred

---

<div class="post-metadata">

**Author:** ![Norm2](https://avatars.discourse-cdn.com/v4/letter/n/3bc359/32.png) [@Norm2](https://discuss.rubyonrails.org/u/Norm2)\
**Post date:** [February 23, 2009, 10:37pm UTC](https://discuss.rubyonrails.org/t/background-process/39697/4 "2009-02-23T22:37:16Z")

</div>

Ankit Parekh wrote:

> ```ruby
> 
> thanks for your reply but i dont want to run something like a cron job or nething.
> Since my method is very long i want it to run in background. So that the user dont need to wait on that page while the process is going on.
> Is there something where i can define that a particular method should run in background.
> Thanks
> 
> ```

I understand why you want to run it in the background but…what happens if there is an error? I do not write perfect code or test 100% of possible code paths or run on failproof hardware so there is always a possibility of an error. You will seem to have the situation where the user thinks everything was processed and saved into the db but that might not be true. I would not be happy if that happened with my data. Personally I would probably want to wait to see all was really successful.

---

<div class="post-metadata">

**Author:** ![rob\_doan](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@rob\_doan](https://discuss.rubyonrails.org/u/rob_doan)\
**Post date:** [March 1, 2009, 10:31pm UTC](https://discuss.rubyonrails.org/t/background-process/39697/5 "2009-03-01T22:31:40Z")

</div>

I think you can use ActiveMQ and Activemessaging plugin

Frederick Cheung wrote:
