Can't get scheduled tasks to work in plugin.

Can't get scheduled tasks to work in plugin.

by Tom Smith -
Number of replies: 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?

Average of ratings: -
In reply to Tom Smith

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

by 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 

In reply to Tom Smith

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

by 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


Average of ratings: Useful (1)
In reply to Adrian Lorenc

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

by Sam Chaffee -
Picture of 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.

Average of ratings: Useful (3)
In reply to Sam Chaffee

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

by Paul Holden -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of 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 approve

Average of ratings: Useful (1)