Forum OpenACS Development: Re: Schedule a procedure to run on 1st of every month in project open.

I guess many of as are not sure, what the problem is. one can easily provide e.g. a parameter for a fproc foo to determine, whether you want to run it manually or not. In the example below, just call "foo" without parameter to call it manually...
ad_proc -public foo {
    {-batch_p 0}
} {
    @param patch_p run only on every 1st
} {
    # guard run in "batched mode"
    if {$batch_p && [clock format [clock seconds] -format "%e"] != 1} { 
    # otherwise just do it

    ns_log notice "running "

# ... register with parameter for batched mode
ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 0 0] foo -batch_p 1
Hi Gustaf,

This will solve the problem partially. As I don't need to call my procedure daily. Please provide something like "bind -time", which works in Project Open to run my procedure on 1st of every month and also to manually invoke the procedure.


the solution i have pasted allows you to call an anytime foo maually. The function will be called as well every day, but the guard makes sure that the function body will be called only on the 1st of every month. Otherwise the function will return doing nothing.

Ok, last attempt: To make the behavior even more explicit, which one can use of many different functions should be called on every 1st:
define a function run_on_every_first and pass it an argument to a plain function (without guard):

proc -public run_on_every_first {proc args} {
    if {[clock format [clock seconds] -format "%e"] != 1} {
        # it is not the first, do nothing 

    # use eval in case, proc has arguments
    eval $proc $args

# ... register which proc should be run on every 1st.
ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 0 0] run_on_every_first YOUR_FUNCTION

Anyhow, if you have more complex needs (there are no indications from your postings), maybe the cronjob package can help you: