Can't get scheduled tasks to work in plugin.

Can't get scheduled tasks to work in plugin.

Tom Smith -
回帖数:5

I'm developing a plugin that automatically imports gradebook from CSV-file in server.

I have following files on my plugin directory (local/flagimport/):

version.php
settings.php
db/tasks.php
classes/task/import_gradebook.php

I have tried incrementing version number and reinstalling plugin but it doesn't add my scheduled task anywhere and task doesn't run.

What am I doing wrong?

回复Tom Smith

Re: Can't get scheduled tasks to work in plugin.

Tom Smith -

Contents of my plugins files:

Content of import_gradebook.php: pastebin.com/ppAEtr5m

Content of tasks.php: pastebin.com/3NPsDBry 

Content of version.php: pastebin.com/ZADkTsvC 

Content of settings.php: pastebin.com/iJRc9bkB 

回复Tom Smith

Re: Can't get scheduled tasks to work in plugin.

Adrian Lorenc -

Hi

I think it is bug in Moodle, scheduled tasks implemented in local plugins are not performed by cron job

core\plugininfo\local does not overwrite get_enabled_plugins method, it returns NULL for all local plugins

get_next_scheduled_task method checks if plugin is enabled, 

                if ($plugininfo) {
                    if (!$task->get_run_if_component_disabled() && !$plugininfo->is_enabled()) {
                        $lock->release();
                        continue;
                    }
                }

is_enabled() returns NULL for all local plugins so task is not performed


回复Adrian Lorenc

Re: Can't get scheduled tasks to work in plugin.

Sam Chaffee -
Core developers的头像

You're right, Adrian - it was fixed in 2.8.1 with MDL-48156. If you're not on a Moodle version >= 2.8.1 it looks like it would be pretty safe to backport.

回复Sam Chaffee

Re: Can't get scheduled tasks to work in plugin.

Paul Holden -
Core developers的头像 Moodle HQ的头像 Moodle Workplace team的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像 Testers的头像

The bug you've linked to only affected 2.8 so you wouldn't need to backport anything to a version prior to that - I can confirm scheduled tasks from local plugins are working fine in the 2.7 branch as we're using that here 满意