How to Run Scheduled Tasks?

Hi,

I'm coding a scheduling application where reminders are sent out to users at date-times specified by the users. What's the best way to do this?

Thanks! :slight_smile:

Bob

I'm coding a scheduling application where reminders are sent out to users at date-times specified by the users. What's the best way to do this?

On a *nix server, you'll want to use cron. On a Windows server, you might be able to use Scheduled Tasks.

An often-adopted approach is to create a "maintenance/scheduling" controller whose actions are invoked by wget through cron. The following example crontab line will hit your controller hourly:

0 * * * * wget -O - -q http://www.domain.tld/maintenance

Roderick

Roderick van Domburg wrote:

I'm coding a scheduling application where reminders are sent out to users at date-times specified by the users. What's the best way to do this?

On a *nix server, you'll want to use cron. On a Windows server, you might be able to use Scheduled Tasks.

As suggested above, you can use Unix cron / Windows scheduled tasks to run a Rails rake task.

http://www.fallenrogue.com/articles/168-Script-vs-Rake

Create a new file in lib/tasks with the extension .rake with your required task. To invoke it simply cd to your rails directory and run rake with your task name (optionally specify the Rails environment). The code inside the task will have full access to your Rails environment including models.

cd /path/to/rails/application rake <task_name> RAIL_ENV=production

Ben

>> I'm coding a scheduling application where reminders are sent out to >> users at date-times specified by the users. What's the best way to

do

>> this? > > On a *nix server, you'll want to use cron. On a Windows server, you > might be able to use Scheduled Tasks.

As suggested above, you can use Unix cron / Windows scheduled tasks to run a Rails rake task.

That *is* a better option. And another PHP-ism flies out the window...

Roderick

Ben wrote:

cd /path/to/rails/application rake <task_name> RAIL_ENV=production

Oops, I made a small typo, that should be RAILS_ENV=production

Roderick van Domburg wrote:

On a *nix server, you'll want to use cron. On a Windows server, you might be able to use Scheduled Tasks.

An often-adopted approach is to create a "maintenance/scheduling" controller whose actions are invoked by wget through cron. The following example crontab line will hit your controller hourly:

0 * * * * wget -O - -q http://www.domain.tld/maintenance

Roderick

On Windows, I use PyCron for this and it's not bad. Just search Google for it.

Cheers Mohit.