Forum OpenACS Q&A: What is the proper method to schedule a procedure?

I am attempting to schedule a report to be compiled and sent on the first of every month.
I have found the procedures ad_schedule_proc that calls ns_schedule_proc, ns_schedule_daily, or ns_schedule_weekly.
None of these seem to fit perfectly, however I can see scheduling a script to run daily, at say 02.00.00, to look to see if it is the first of the month and if it is have the report run.

Is this a good way to accomplish this task?  If so, do I need to keep track of the schedule id on my own that gets returned?
Is there a better alternative to this method?

Also, how do I get it to be automatically scheduled if and when the server is reset or restarted?


Posted by Caroline Meeks on
Checkout the cronjob package (in contrib I think). It is a little package that does basically exactly what you describe.

It has some short comings, for instance if your server happens to be down and 2am it won't run it when it come back up.

Posted by Tom Jackson on

Try the cronjob package. It was designed for running reports on the odd schedules set by managers. One downside is that if the server isn't running when a cron was scheduled, it will not run later on. But you can login at any time and run any of your defined crons. It will run just as if it had been scheduled.

If you just provide and sql statement to run, it will format the result as an html table and email the result. Otherwise, you can run any tcl code as well.

Posted by Steve Manning on
<blockquote>Also, how do I get it to be automatically scheduled if and when the server is reset or restarted?

To have a process automatically scheduled on server startup place a call to ad_scheduled_proc in  /packages/mypackage/tcl/mypackage-init.tcl

Take a look at packages/acs-messaging/tcl/acs-messaging-init.tcl for an example.

    - Steve