Background process (cron job) and business rules + database

My application needs to send email reminders to people before certain
events. I think cron job is the way to go which will run every hour.

Rather than putting the database connection and all the business rules
in
the shell script , I was wondering if there is a better way. I haven’t
used
rake but is it possible to write a rake job and execute it through a
cron
job. Any suggestions on handling these kinds of issues.

Thanks.

My application needs to send email reminders to people before certain
events. I think cron job is the way to go which will run every hour.

Rather than putting the database connection and all the business rules in
the shell script , I was wondering if there is a better way. I haven’t used
rake but is it possible to write a rake job and execute it through a cron
job. Any suggestions on handling these kinds of issues.

Define a method in the appropriate model and then call it like this from
cron:

/path/to/rails_root/script/runner “MyModel.my_method(arg, arg)”

Then you’ll have access to your db connection just like you would
normally
as well as all your other models, etc.

-philip

On 11/4/06, Philip H. [email protected] wrote:

cron:

/path/to/rails_root/script/runner “MyModel.my_method(arg, arg)”

Then you’ll have access to your db connection just like you would normally
as well as all your other models, etc.

-philip

You are forgetting backgroundrb!!!

gnufied

There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.

Thanks guys.

I didn’t know about script/runner.

I also missed out on backgrounddrb.

-=-

On Nov 4, 2006, at 3:59, Neeraj K. wrote:

Rather than putting the database connection and all the business
rules in the shell script , I was wondering if there is a better
way. I haven’t used rake but is it possible to write a rake job and
execute it through a cron job. Any suggestions on handling these
kinds of issues.

It sure is possible to run a rake command from cron. However, you can
also use script/runner for this:

./script/runner “your code goes here”

So for example script/runner “require ‘send_reminders’” or script/
runner ‘Reminder.deliver_all’ can be run from your cronjob.


Jakob S. - http://mentalized.net