Ad hoc task failed to load

Ad hoc task failed to load

by Gabriel José Guedes da Silva -
Number of replies: 2

I've been developing a plugin with an hoc task
I have followed the ad hoc tutorial in https://docs.moodle.org/dev/Task_API

  1. Created file take_over_the_world.php inside /myplugin/classes/tasks
  2. imported using: require_once './classes/tasks/take_over_the_world.php';
  3. Instantiated the task inside the plugin: $domination = new take_over_the_world(); ,etc...

But i can't see my task anywhere, except in "path/to/moodle/admin/cron.php?password=xxx" where i can see the following error: 

++ Failed to load task: \take_over_the_world ++ 

* line 292 of /lib/classes/task/manager.php: call to debugging() 

* line 595 of /lib/classes/task/manager.php: call to core\task\manager::adhoc_task_from_record() 

* line 184 of /lib/cronlib.php: call to core\task\manager::get_next_adhoc_task() 

* line 76 of /lib/cronlib.php: call to cron_run_adhoc_tasks() * line 81 of /admin/cron.php: call to cron_run()

Average of ratings: -
In reply to Gabriel José Guedes da Silva

Re: Ad hoc task failed to load

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
It would be easier if we could see some code, but my first guess would be, did you set the namespace at the top of the file to: \local_myplugin\task

(assuming 'myplugin' is a 'local' plugin, you haven't stated).
Average of ratings: Useful (1)
In reply to Davo Smith

Re: Ad hoc task failed to load

by Gabriel José Guedes da Silva -
Simple as you mentioned...
  • Declared "namespace block_lancarnotas\tasks;" on top of task file named: take_over_the_world.php
  • Included with "use block_lancarnotas\tasks\take_over_the_world;" instead of require_once...