Can't get scheduled tasks to work in plugin.

Can't get scheduled tasks to work in plugin.

Tom Smith -
Atsakymų skaičius: 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?

Pažymių vidurkis: -
Atsakymas į 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 

Atsakymas į 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


Atsakymas į Adrian Lorenc

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

Sam Chaffee -
Core developers paveikslėlis

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.

Atsakymas į Sam Chaffee

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

Paul Holden -
Core developers paveikslėlis Moodle HQ paveikslėlis Moodle Workplace team paveikslėlis Particularly helpful Moodlers paveikslėlis Peer reviewers paveikslėlis Plugin developers paveikslėlis Testers paveikslėlis

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 pritariantis