Managing scheduled tasks

It looks to me that this line

add_action('obr_scheduled_task', array(&$this, 'obr_activate_scheduled_task'));

should be

add_action('obr_scheduled_task', array(&$this, 'obr_scheduled_task'));

otherwise you are re-scheduling on every page visit.

Edit:

Here is a logger that can be useful when debugging wp-cron:

function my_logger($var){
    $logfile="/tmp/logger.txt"; // EDIT this to your needs
    file_put_contents($logfile, date("Y-m-d: H:i:s",time())." --- ".print_r($var, true)."\n", FILE_APPEND);
}

You can use it inside your class functions with relevant debug messages,

 my_logger("My Class construction");
 my_logger("Running the cron function");

and the logfile will look like this:

2013-02-20: 14:00:43 --- My Class construction
2013-02-20: 14:00:53 --- Running the cron function

Hope this helps.

Leave a Comment