batch processes interacting with ROR data

The application I am working on needs a nightly process to comb through the database and make periodic changes.

What is the best way to implement a script in order to leverage the existing database connection management and active record functionality?

Thanks.

Dan Munk wrote:

The application I am working on needs a nightly process to comb through the database and make periodic changes.

What is the best way to implement a script in order to leverage the existing database connection management and active record functionality?

Tell the OS to periodically run a script using 'cron', or the Task Manager, or some derivative therof. Some are called 'at'.

The script may run something like this:

   ruby script/runner "load('my_batch.rb')"

my_batch.rb then contains a batch of Ruby, enjoying the complete Rails context. IIRC.

There might be other ways to invoke the runner script. --help didn't confess them.

Thanks Phlip,

I have no problem with the scheduling of the script. I really want to understand how people are writing the scripts themselves share the existing database connections and use active record. For instance:

1. Periodic web service invocation. 2. External script.

Thanks, Dan

Fred wrote:

I think you're looking for difficulties where there are none. The script run by cron (for example) will have its own database connection, just as each of your mongrels/fcgi listeners has one, and can use ActiveRecord just as your controllers would or you would from script/console.

I solved that one, and re-used the connection. I did it the extra-sick way. I wrote a private action, available only in non-production mode, and then I hit it with a simulated web browser.

There's a less-sick way, right?

But all the pieces were just laying around, tempting me, saying "put me together like thiiiiis!!"

There are examples of how to use ActiveRecord outside of rails in the Rails Recipes book, it may be of use.

Dan Munk wrote:

Thanks Phlip,

I have no problem with the scheduling of the script. I really want to understand how people are writing the scripts themselves share the existing database connections and use active record. For instance:

1. Periodic web service invocation. 2. External script.

This is Rails - you don't share anything other than the database itself. Batch scripts and offload scripts run in their own separate process space unhindered by the Web facing application processes.

NeilW