# Running external scripts that know about a minimal Rails env

**URL:** <https://www.ruby-forum.com/t/running-external-scripts-that-know-about-a-minimal-rails-env/56794>\
**Category:** Rails\
**Created:** [April 4, 2006, 4:14am UTC](https://www.ruby-forum.com/t/running-external-scripts-that-know-about-a-minimal-rails-env/56794 "2006-04-04T04:14:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![n8agrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7feea3/32.png) [@n8agrin](https://www.ruby-forum.com/u/n8agrin)\
**Post date:** [April 4, 2006, 4:14am UTC](https://www.ruby-forum.com/t/running-external-scripts-that-know-about-a-minimal-rails-env/56794/1 "2006-04-04T04:14:06Z")

</div>

I’ve been exploring the options for running external scripts from the  
Rails env.

The list I have is this:

Cron  
ScriptRunner (in the script/ dir under rails projects)  
RailsCron

The most likely candidate for me is the ScriptRunner because my external  
script needs to know about a model which it has to save to the database  
from my Rails environment, and it needs to start running as soon as I  
tell it to. Unfortunately, running this external command many times in  
a row is a bottleneck since each ScriptRunner instance has to load up  
the entire rails env.

What I’m wondering is what is the easiest way to create a script which  
knows only about the model I need to work with, and it’s database  
location, so that my script doesn’t need to load the entire Rails env.

I’m thinking if I can load the activerecord gem with a slim config  
setup, that might work, but I’m not sure how to use activerecord outside  
the context of the Rail’s env.

Anyone else ever tackle this issue?

---

<div class="post-metadata">

**Author:** ![n8agrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7feea3/32.png) [@n8agrin](https://www.ruby-forum.com/u/n8agrin)\
**Post date:** [April 4, 2006, 8:22am UTC](https://www.ruby-forum.com/t/running-external-scripts-that-know-about-a-minimal-rails-env/56794/2 "2006-04-04T08:22:02Z")

</div>

On 4/3/06, Nate A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> script needs to know about a model which it has to save to the database  
> setup, that might work, but I’m not sure how to use activerecord outside

Hi Nate,  
To run a minimal script that just loads the activerecord gem and  
connects to mysql on localhost takes just over a second on my G4  
powerbook, and the same amount of time on my dedicated linux server.

The other option is a persistant Rails environment, of which RailsCron  
is the only one I am aware. Let me know how you like it.

–  
Kyle M.  
Chief Technologist  
E Factor Media // FN Interactive  
removed\_email\_address@domain.invalid  
1-866-263-3261
