General developer forum

Upgrade error after converting cron to scheduled tasks

 
it's me
Upgrade error after converting cron to scheduled tasks
Core developersParticularly helpful MoodlersPlugin developers

Hi,

I did move cron job to scheduled tasks according to the guidelines in the docs. But my scheduled tasks are not loaded on upgrade nor registered in the scheduled tasks list.

Link to the module:

https://github.com/dasistwas/moodle-mod_newsletter

Error message on cli upgrade:

-->mod_newsletter
++ 2018091408: Success (0.02 seconds) ++
++ Failed to load task: \mod_newsletter\task\send_newsletter ++
* line 309 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 824 of /lib/upgradelib.php: call to core\task\manager::reset_scheduled_tasks_for_component()
* line 508 of /lib/upgradelib.php: call to upgrade_plugins_modules()
* line 1850 of /lib/upgradelib.php: call to upgrade_plugins()
* line 181 of /admin/cli/upgrade.php: call to upgrade_noncore()
++ Failed to load task: \mod_newsletter\task\process_bounces ++
* line 309 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 824 of /lib/upgradelib.php: call to core\task\manager::reset_scheduled_tasks_for_component()
* line 508 of /lib/upgradelib.php: call to upgrade_plugins_modules()
* line 1850 of /lib/upgradelib.php: call to upgrade_plugins()
* line 181 of /admin/cli/upgrade.php: call to upgrade_noncore()
++ Success (0.06 seconds) ++
Command line upgrade completed successfully.
Code of tasks.php file:
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => 'mod_newsletter\task\send_newsletter',
'blocking' => 0,
'minute' => '*',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*'
),
array(
'classname' => 'mod_newsletter\task\process_bounces',
'blocking' => 0,
'minute' => '0',
'hour' => '23,3',
'day' => '*',
'month' => '*',
'dayofweek' => '*'
)
);

Location of the classes:
moodle-mod_newsletter/classes/tasks/process_bounces.php
moodle-mod_newsletter/classes/tasks/send_newsletter.php

Code for bounces

namespace mod_newsletter\task;
class process_bounces extends \core\task\scheduled_task {
public function get_name() {
// Shown in admin screens.
return get_string('process_bounces', 'mod_newsletter');
}
public function execute() {
$config = get_config('mod_newsletter');
if ($config->enablebounce == 1) {
require_once ('classes/bounce/bounceprocessor.php');
$bounceprocessor = new \mod_newsletter\bounce\bounceprocessor($config);
$bounceprocessor->open_mode = CWSMBH_OPEN_MODE_IMAP;
if ($bounceprocessor->openImapRemote()) {
$bounceprocessor->process_bounces();
$bounceprocessor->update_health();
} else {
mtrace(
"!!! FAILURE to use IMAP: PHP imap does not seem to be enabled on your server!!!");
}
}
}
}

Code for sending newsletter:

namespace mod_newsletter\task;
use core_user;
use cron_helper;
use html_writer;
use mod_newsletter_issue_form;
use stdClass;
use mod_newsletter\newsletter;
use moodle_url;
class send_newsletter extends \core\task\scheduled_task {
public function get_name() {
// Shown in admin screens.
return get_string('send_newsletter', 'mod_newsletter');
}
public function execute() {
.....code.....

Maybe I am just to blind to see what is wrong. Using Moodle 3.4 for upgrading to the new mod_newsletter version.

Any help is very welcome.

Kind regards,
David


 
Average of ratings: -
Davo
Re: Upgrade error after converting cron to scheduled tasks
Core developersParticularly helpful MoodlersPlugin developers

Just to confirm, you say that the locations for the classes are:

moodle-mod_newsletter/classes/tasks/process_bounces.php
moodle-mod_newsletter/classes/tasks/send_newsletter.php

Surely that should be:
[main Moodle code directory]/mod/newsletter/classes/task/process_bounces.php

Note both the starting part of the path (/mod/newsletter) and the singular 'task' after classes (which should match the namespace).

 
Average of ratings: Useful (2)
it's me
Re: Upgrade error after converting cron to scheduled tasks
Core developersParticularly helpful MoodlersPlugin developers
Hi Davo,

thank you. That was definitely a case of spot-blindness. As you pointed out, the s was the problem tasks->task works perfect now.

Kind regards,
David
 
Average of ratings: Useful (1)