Reputation: 26283
I am trying to add a cron job in moodle block.
I am following this tutorial on moodle 3.0 https://docs.moodle.org/dev/Blocks#Responding_to_Cron
When I run /admin/cron.php, my cron job does not execute.
Am I missing anything here?
Upvotes: 1
Views: 1134
Reputation: 10221
The old way uses cron like this:
/blocks/yourblockname/block_yourblockname.php
class block_yourblockname extends block_base {
...
public function cron() {
// Your code.
}
and in /blocks/yourblockname/version.php
$plugin->cron = xxxx; // Cron interval in seconds. 0 means no cron.
The new way is to use scheduled tasks - https://docs.moodle.org/dev/Task_API
UPDATE: As mentioned by @Developer
If you change the cron value or add a new task then you will also need to increment the version number
$plugin->version = xxxx;
Upvotes: 1