Info about running regular tasks with cron

What commands to use, and good approach to testing
This commit is contained in:
Jeremy Shipman 2013-04-15 10:47:59 +12:00
parent c02d7e4c2e
commit 4db5f75298

View File

@ -123,4 +123,26 @@ Step 3: Use sake to start and stop your process
Note that sake processes are currently a little brittle, in that the pid and log files are placed in the site root
directory, rather than somewhere sensible like /var/log or /var/run.
directory, rather than somewhere sensible like /var/log or /var/run.
### Running Regular Tasks With Cron
On a unix machine, you can typically run a scheduled task with a [cron job](http://en.wikipedia.org/wiki/Cron),
using one of the following command-line calls:
```
/path/to/site_root/framework/sake MyTask
php /path/to/site_root/framework/cli-script.php MyTask
```
If you find that your cron job appears to be retrieving the login screen, then you may need to use `php-cli`
instead. This is typical of a cPanel-based setup.
```
php-cli /path/to/site_root/framework/cli-script.php MyTask
```
A good approach to setting up and testing your task to run with cron is:
1. Try running the task via the command-line on your server. `/path/to/site_root/framework/sake MyTask`
2. Set up a cron job to run the task every minute. `* * * * * /path/to/site_root/framework/sake MyTask`
3. Finally, set the task to run when you want it to. `0 2 * * * /path/to/site_root/framework/sake MyTask` (2am)