# Crontab utility for rails

**URL:** <https://www.ruby-forum.com/t/crontab-utility-for-rails/140031>\
**Category:** Rails\
**Created:** [June 10, 2008, 7:25am UTC](https://www.ruby-forum.com/t/crontab-utility-for-rails/140031 "2008-06-10T07:25:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 10, 2008, 7:25am UTC](https://www.ruby-forum.com/t/crontab-utility-for-rails/140031/1 "2008-06-10T07:25:04Z")

</div>

to run any function at periodically in SYSTEM then we can use crontab  
tool.  
for the same purpose,is there anything into RAILS project ?

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 10, 2008, 7:47am UTC](https://www.ruby-forum.com/t/crontab-utility-for-rails/140031/2 "2008-06-10T07:47:25Z")

</div>

BackgroundRB I think can run scheduled tasks.

On Tue, Jun 10, 2008 at 2:55 PM, Pokkai D. \<  
removed\_email\_address@domain.invalid\> wrote:

> ## to run any function at periodically in SYSTEM then we can use crontab tool. for the same purpose,is there anything into RAILS project ?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Appreciated my help?  
Recommend me on Working With Rails  
[http://workingwithrails.com/person/11030-ryan-bigg](http://workingwithrails.com/person/11030-ryan-bigg)

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 10, 2008, 11:34am UTC](https://www.ruby-forum.com/t/crontab-utility-for-rails/140031/3 "2008-06-10T11:34:44Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Tuesday 10 June 2008 07:25:04 Pokkai D. wrote:

> to run any function at periodically in SYSTEM then we can use crontab  
> tool.  
> for the same purpose,is there anything into RAILS project Â ?

Your Rails application will include a script/runner script. You can use  
it to run (slow-loading) code in the context of your Rails application  
from cron jobs. Just remember to set RAILS\_ENV=production in the  
crontab in production. 🙂

If your jobs must fire frequently, consider something like backgroundrb  
instead.

Ciao,  
Sheldon.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFITkpzpGJX8XSgas0RAvJVAKCXUGf+DqGr16L3YeoURfIS9WjHcgCfcxYO  
CAo0TZv6hbMUaRCWHAVVJko=  
=MVCM  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 10, 2008, 1:19pm UTC](https://www.ruby-forum.com/t/crontab-utility-for-rails/140031/4 "2008-06-10T13:19:14Z")

</div>

Sheldon H. wrote:

> -----BEGIN PGP SIGNED MESSAGE-----  
> Hash: SHA1
> 
> On Tuesday 10 June 2008 07:25:04 Pokkai D. wrote:
> 
> Your Rails application will include a script/runner script. You can use  
> it to run (slow-loading) code in the context of your Rails application  
> from cron jobs. Just remember to set RAILS\_ENV=production in the  
> crontab in production. 🙂
> 
> If your jobs must fire frequently, consider something like backgroundrb  
> instead.
> 
> Ciao,  
> Sheldon.  
> -----BEGIN PGP SIGNATURE-----  
> Version: GnuPG v1.4.6 (GNU/Linux)
> 
> iD8DBQFITkpzpGJX8XSgas0RAvJVAKCXUGf+DqGr16L3YeoURfIS9WjHcgCfcxYO  
> CAo0TZv6hbMUaRCWHAVVJko=  
> =MVCM  
> -----END PGP SIGNATURE-----

i thing

sleep(1.hour) inside another Thread

will it give any problem ?

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 16, 2008, 3:35am UTC](https://www.ruby-forum.com/t/crontab-utility-for-rails/140031/5 "2008-06-16T03:35:58Z")

</div>

Quoting Sheldon H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> it to run (slow-loading) code in the context of your Rails application  
> from cron jobs. Just remember to set RAILS\_ENV=production in the  
> crontab in production. 🙂

I’d suggest changing to your application’s home/root directory and then  
invoking the function with script/runner. I found the results variable  
until  
I added the change directory. It has been rock solid ever since. For  
example:

3-58/5 \* \* \* \* cd /home/jeff/Rails/amethyst; nice ./script/runner -e  
development ‘Preload.preload’ &\> /dev/null

Runs at 3, 8, 13, 18, … minutes after the hour. Calls the preload()  
function in the Preload module in development mode. And drops the  
output into  
the bit bucket. Leave off the “&\> /dev/null” part until you are sure it  
is  
running without problems. Depending on your setup (e.g. production  
vs. development databases) you may wish to run in production mode. It  
may run  
faster.

HTH,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 11, 2008, 4:49pm UTC](https://www.ruby-forum.com/t/crontab-utility-for-rails/140031/6 "2008-06-11T16:49:03Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Tuesday 10 June 2008 13:19:14 Pokkai D. wrote:

> sleep(1.hour) inside another Thread
> 
> will it give any problem ?

Why in another thread? Just put it in the main loop of your script.

Ciao,  
Sheldon.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIT+WvpGJX8XSgas0RAuBCAJ443+P/AMz1pAYfvx8Aw9vc+cTw0wCfT+y/  
z3cAUFGlxC+6SyqPyq59rg8=  
=OWAd  
-----END PGP SIGNATURE-----
