scheduler
You can use the Scheduler module in Xaraya to queue up jobs.
For example, Pubsub allows users to subscribe to events on your system; when an article (in a particular category) is changed or comments are added to a forum, subscribed users will be notified via email.
Or, you can schedule regular backups using Sitetools. And so on.
To run the jobs queued up in the Scheduler, you need a trigger. This trigger can be someone hitting the scheduler module on your site. You can setup a cron job to trigger the scheduler, say, once an hour.
Configure Scheduler Module
On the Scheduler Config screen choose "External Scheduler", and the IP address where your cron job will be running. Use the "Note: you are connected ..." to help decided.
Also note the url that the Trigger specifies, e.g. http://www.mysite.com/?module=scheduler
Test Trigger from Command Line
From the command line on that system, run
curl "http://www.mysite.com/?module=scheduler"
If it comes back (wading through the html) with something like
Starting jobs
pubsub admin processq succeeded :
1
then you're cool. Otherwise check the Source IP settings.
Make a Scheduler Theme
We dont need all the html, so I create a very simple theme (e.g. from the empty/ theme) named "scheduler", that all it has is a pages/default.xt that contains
<xar:module id="modulespace" main="true" />
Then you can trigger with
curl "http://www.mysite.com/?module=scheduler&theme=scheduler"
Write a Shell Script
Once that's working put the curl command into a shell script, such as scheduler.sh
#!/bin/sh
/usr/local/bin/curl -v "http://www.mysite.com/?module=scheduler&theme=scheduler" >>/home/xaraya/crondump.txt
Note that I direct output to a file, at least until we're sure things are working. Make sure it's chmod 755
Create the Crontable
Next, create the crontable. Make a file like crontable.xaraya with something like
# hourly triggers for xaraya scheduler
0 * * * * sh /home/me/scheduler.sh
And add it to cron with
crontab crontable.xaraya
Make sure its there with
crontab -l
That's it, should be good to go.
Crontable Format
Wikipedia has a nice article: http://en.wikipedia.org/wiki/Cron
# append a message to file every minute, tests cron is working
* * * * * echo "hello from crontab" >>/home/me/crondump.txt
# hourly triggers for xaraya scheduler
0 * * * * curl "http://www.mysite.org/?module=scheduler&theme=scheduler"
# (Use to post in the top of your crontab)
# ----------------- minute (0 - 59)
# | -------------- hour (0 - 23)
# | | ----------- day of month (1 - 31)
# | | | -------- month (1 - 12)
# | | | | ----- day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
Comments
scheduler and Security
One thing that you will want to keep track of is when you create scheduled functions that require access to restricted content. Your website does not automatically recognize CRON as an administrative user. You will need to create an account for CRON to use and: * setting cookie options in your CURL * pointing the URL at authsystem/login with the scheduler as the "redirecturl".
Example: /usr/bin/curl -L -b /home/miragelab/cookies.txt -c /home/miragelab/cookies.txt -o /home/miragelab/crondump.txt -d "module=authsystem&func=login&uname=CRONuser&pass=CRONpass&redirecturl=index.php %3Fmodule%3Dscheduler%26pageName%3Dmodule" http://www.miragelab.com/index.php
New Comment