cron function is'nt working

Re: cron function is'nt working

by Paul Nicholls -
Number of replies: 0

I suspect you're actually getting a fatal error in there, because:
require_once($CFG->libdir . '/blocks/autobadge/locallib.php');
is attempting to include a file which doesn't exist.

$CFG->libdir points to the "lib" directory within your Moodle codebase, but "blocks" is a top-level directory (it sits alongside the "lib" directory, not inside it).  $CFG->dirroot points to your Moodle codebase, so:
require_once($CFG->dirroot . '/blocks/autobadge/locallib.php');
should do the trick.  If there are no other (fatal) errors, it should start working - if not, make sure you have debugging enabled and check the cron logs for errors.  Also note that as per Edwin's post, if you're on 2.7 or above and your legacy cron task has been failing (due to your block's cron function failing), you may need to adjust the retry delay so that it runs on a reasonable schedule.

If your block doesn't need to support versions older than Moodle 2.7, you could also look at using the Task API instead of a legacy cron function; if you have command-line access to the server, you can run an individual scheduled task directly using the admin/tool/task/cli/schedule_task.php script, which means less wading through logs to find any errors from your code.