Scheduled Task in Block Plugin throwing errors on upgrade

Scheduled Task in Block Plugin throwing errors on upgrade

by Scott Dellinger -
Number of replies: 4

I'm attempting to add a scheduled task to a block plugin I'm working on and have been banging my head against a wall the last couple of days. When I upload/upgrade the plugin I receive the following message about the newly added task:

Failed to load task: \process_integrityadvocate
line 270 of \lib\classes\task\manager.php: call to debugging()
line 68 of \lib\classes\task\manager.php: call to core\task\manager::scheduled_task_from_record()
line 88 of \lib\classes\task\manager.php: call to core\task\manager::load_default_scheduled_tasks_for_component()
line 959 of \lib\upgradelib.php: call to core\task\manager::reset_scheduled_tasks_for_component()
line 446 of \lib\upgradelib.php: call to upgrade_plugins_blocks()
line 1754 of \lib\upgradelib.php: call to upgrade_plugins()
line 699 of \admin\index.php: call to upgrade_noncore()

Here is block_integrityadvocate_review.php

class block_integrityadvocate_review extends block_base {
    public function init() {
        $this--->title = get_string('integrityadvocate_review', 'block_integrityadvocate_review');
    }
    function applicable_formats() {
        return array('all' => true);
    }
    public function get_content() {
	// This works fine
    }
}

\db\tasks.php

$tasks = [
    [
        'classname' => 'block_integrityadvocate_review\task\process_integrityadvocate',
        'blocking' => 0,
        'minute' => '*',
        'hour' => '*',
        'day' => '*',
        'month' => '*',
        'dayofweek' => '*',
    ],
];

\classes\tasks\process_integrityadvocate.php

namespace block_integrityadvocate_review\task;
class process_integrityadvocate extends \core\task\scheduled_task {
    public function get_name() {
        return get_string('process_integrityadvocate', 'block_integrityadvocate_review');
    }
    public function execute() {
        // perform actions here
    }
}

version.php

$plugin->component = 'block_integrityadvocate_review';
$plugin->version = 2016122905;
$plugin->requires = 2014051200;

I'm pretty sure I'm messing something easy up, but for the life of me I can't seem to figure out what it is. Any assistance would be appreciated.

Average of ratings: -
In reply to Scott Dellinger

Re: Scheduled Task in Block Plugin throwing errors on upgrade

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

What about moving your \classes\tasks\process_integrityadvocate.php into \classes\task\process_integrityadvocate.php?

In reply to Renaat Debleu

Re: Scheduled Task in Block Plugin throwing errors on upgrade

by Scott Dellinger -

Apologies... that was a typo... it is currently in /classes/task.

In reply to Scott Dellinger

Re: Scheduled Task in Block Plugin throwing errors on upgrade

by Scott Dellinger -

Not sure what I did... after a full uninstall/reinstall of the plugin no errors are reported. Looks like it's all working properly now. Thanks for looking!

In reply to Scott Dellinger

Re: Scheduled Task in Block Plugin throwing errors on upgrade

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

If you add a class, you will not be able to reference it by its namespace until you have purged the Moodle cache. 

When you do that Moodle rebuilds its list of classes. Thats probably why your code was perfect, but it took the uninstall/uninstall for Moodle to notice how perfect it was.

Average of ratings: Useful (1)