我正在尝试按照以下说明在moodle-cron-api中调度任务:https://docs.moodle.org/dev/Task_API.
根文件夹位于/local,根文件夹的名称为mod_hygene。
我有一个cut_my_toe_nails.php在/local/mod_hygene/classes/task它是:
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';
}
}
下面是/mod_hygene/db/tasks. php文件夹:
$tasks = [
[
'classname' => 'mod_hygene\task\cut_my_toe_nails',
'blocking' => 0,
'minute' => '*',
'hour' => '*',
'day' => '*',
'month' => '1,7',
'dayofweek' => '*',
],
];
正如你所看到的,任务应该每分钟运行一次。
docker-compose up -d --build moodle
在终端我应该看到'do'打印每分钟。但是,我没有看到任何东西。我徘徊到网站管理/服务器/任务计划。在那里我没有看到这个任务。但我检查了网站管理/插件/插件概述,可以找到local_mod_hygene在本地插件。
有人能帮我吗?我需要对Dockerfile做一些修改吗?
1条答案
按热度按时间pvcm50d11#
只是一个提示,不要使用前缀
mod_
为本地插件,它可能会被混淆为一个活动插件在mod
文件夹。假设您的代码在
/local/hygene/
中任务文件应为
/local/hygene/classes/task/cut_my_toe_nails.php
类命名空间应为
任务文件应为
/local/hygene/db/tasks.php
,其中安装后,检查是否通过启用了任务
站点管理〉服务器〉任务
或直接到
yourwebsite/admin/tool/task/scheduledtasks.php
如果已安装并启用,则从命令行运行它以进行测试。
首先查看其是否已列出-如果未列出,则说明安装不正确
如果已列出,请记下名称并手动运行任务-请注意,必须使用
\\
转义\
如果任务运行正常,则等待cron
或者,根据设置,您可以在以管理员身份登录时通过
yourmoodlewebsite/admin/cron.php
手动运行cron或从命令行