# Need to run controller code periodically in the background

**URL:** <https://www.ruby-forum.com/t/need-to-run-controller-code-periodically-in-the-background/72434>\
**Category:** Rails\
**Created:** [October 17, 2006, 8:07am UTC](https://www.ruby-forum.com/t/need-to-run-controller-code-periodically-in-the-background/72434 "2006-10-17T08:07:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanand83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@sanand83](https://www.ruby-forum.com/u/sanand83)\
**Post date:** [October 17, 2006, 8:07am UTC](https://www.ruby-forum.com/t/need-to-run-controller-code-periodically-in-the-background/72434/1 "2006-10-17T08:07:21Z")

</div>

I need to invoke certain portions of my controller periodically in the  
background without any user initiation [through views].

Currently, I hack this by using an unit test - obviously this wont work  
in a production environment.

Is there a way to invoke / post requests to a controller [with login  
and all] outside of the testing framework?

Any help would be appreciated.

anand

---

<div class="post-metadata">

**Author:** ![sanand83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@sanand83](https://www.ruby-forum.com/u/sanand83)\
**Post date:** [October 17, 2006, 9:45am UTC](https://www.ruby-forum.com/t/need-to-run-controller-code-periodically-in-the-background/72434/2 "2006-10-17T09:45:31Z")

</div>

well that depends what you want excatly.

- the plugin “backgroundrb” can run tasks periodically i guess, outside  
of rails in a new thread.

- ActionView’s Prototype Helper “periodically call remote” can make  
periodical AJAX calls to a controller

---

<div class="post-metadata">

**Author:** ![sanand83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@sanand83](https://www.ruby-forum.com/u/sanand83)\
**Post date:** [October 17, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/need-to-run-controller-code-periodically-in-the-background/72434/3 "2006-10-17T17:31:09Z")

</div>

Thanks Thorsten.

I will check out backgroundrb.

---

<div class="post-metadata">

**Author:** ![sanand83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@sanand83](https://www.ruby-forum.com/u/sanand83)\
**Post date:** [October 18, 2006, 1:49am UTC](https://www.ruby-forum.com/t/need-to-run-controller-code-periodically-in-the-background/72434/4 "2006-10-18T01:49:06Z")

</div>

Joe

Dumb question - so the code in lib has access to rails infrastructure,  
as in full access to models and querying etc?

anand

---

<div class="post-metadata">

**Author:** ![sanand83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@sanand83](https://www.ruby-forum.com/u/sanand83)\
**Post date:** [October 17, 2006, 8:40pm UTC](https://www.ruby-forum.com/t/need-to-run-controller-code-periodically-in-the-background/72434/5 "2006-10-17T20:40:27Z")

</div>

I would code up a function and put it in /lib, then use cron  
script/runner to execute it. No having to mess with logins, etc.

Joe
