LMSouq
moodle-core Open

Adding a cronjob with moodle-cron-api is not working properly

KH
Khabbab Zakaria
1 month ago
3 views
Problem Description
I am trying to schedule a task in moodle-cron-api following the instructions here at: [https://docs.moodle.org/dev/Task_API](https://docs.moodle.org/dev/Task_API). I have the root folder at <moodle>/local and the name of the root folder is mod_hygene. I have a cut_my_toe_nails.php at <moodle>/local/mod_hygene/classes/task which is: ``` namespace mod_hygene\task; /** * An example of a scheduled task. */ class cut_my_toe_nails extends \core\task\scheduled_task { /** * Return the task's name as shown in admin screens. * * @return string */ public function get_name() { return get_string('cutmytoenails', 'mod_hygene'); } /** * Execute the task. */ public function execute() { // Apply fungus cream. // Apply chainsaw. // Apply olive oil. echo 'do'; } } ``` And there is <moodle>/mod_hygene/db/tasks.php: ``` $tasks = [ [ 'classname' => 'mod_hygene\task\cut_my_toe_nails', 'blocking' => 0, 'minute' => '*', 'hour' => '*', 'day' => '*', 'month' => '1,7', 'dayofweek' => '*', ], ]; ``` As you see, the task should run every minute. I run my moodle container via terminal with ``` docker-compose up -d --build moodle ``` In the terminal I should see 'do' printed every minute. But, I am not seeing anything. I hovered to Site Administration/Server/Scheduled Tasks. There I am not seeing this task. But I checked in Site Administration/Plugins/Plugins Overview and could find local_mod_hygene in the Local Plugins. Can anyone help me with it? Do I need to make some changes to the Dockerfile as well?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base