# Execute System command asynchronously in Controller-\>Action

**URL:** <https://www.ruby-forum.com/t/execute-system-command-asynchronously-in-controller-action/195107>\
**Category:** Rails\
**Created:** [September 17, 2010, 2:49am UTC](https://www.ruby-forum.com/t/execute-system-command-asynchronously-in-controller-action/195107 "2010-09-17T02:49:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudheendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e0b2c6/32.png) [@sudheendra](https://www.ruby-forum.com/u/sudheendra)\
**Post date:** [September 17, 2010, 2:49am UTC](https://www.ruby-forum.com/t/execute-system-command-asynchronously-in-controller-action/195107/1 "2010-09-17T02:49:23Z")

</div>

My contoller -\> action executes the ruby script on click of a button  
using System command.  
Ruby Script takes 30seconds to execute.

If two users clicks the button same time in two separate browsers,  
second user execution will start after first user’s reqeust is  
completed.

I need suggestion how to handle this ?

Also is it possible to skip the script execution if it is already  
started by other user ?

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![sudheendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e0b2c6/32.png) [@sudheendra](https://www.ruby-forum.com/u/sudheendra)\
**Post date:** [September 17, 2010, 4:31pm UTC](https://www.ruby-forum.com/t/execute-system-command-asynchronously-in-controller-action/195107/2 "2010-09-17T16:31:36Z")

</div>

Hi,

Two things about your problem …

1st - The behavior that you are describing should only apply to your  
dev environment since you should be able to set up your production  
server to manage more than a single request at time. Anyways, there’s  
always a solution regardless of the environment like…

2nd - Try one of the backgrounders that ruby have right now like:  
backgroundrb - [http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)  
delayed\_jobs - [GitHub - collectiveidea/delayed\_job: Database based asynchronous priority queue system -- Extracted from Shopify](http://github.com/collectiveidea/delayed_job)  
resque (my favorite :D) - [GitHub - defunkt/resque: Moved to resque/resque](http://github.com/defunkt/resque)

They will let you run your system calls as background processes  
without increasing your response time.

## Regards,

Roberto

On Sep 16, 9:49 pm, Sudheendra P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
