Failing to create a new scheduled task

Failing to create a new scheduled task

by Bo Pierce -
Number of replies: 7

Hello,
I having trouble scheduling a new task in this plugin directory that I have created:
/question/type/random/classes/task/

My scheduled task is not listed,

php /admin/tool/task/cli/schedule_task.php --list

and it does not appear in the web interface, either.


I cannot run the scheduled task manually.

$ php <path to>/moodle/admin/tool/task/cli/schedule_task.php --execute='<path to plugin>\classes\task\question_type_random_remove_unused_qs.php'
Task 'classes\task\question_type_random_remove_unused_qs.php' not found
...and I have also tried using '/' instead of '\'


Perhaps there is a problem with my task files, so I have attached them.


I can run the cli cron,

$ sudo service cron start
[sudo] password for user:
start: Job is already running: cron

$ /usr/bin/php /path/to/moodle/admin/cli/cron.php
Cron script completed correctly
Cron completed at 20:43:41. Memory used 17.4MB.
Execution took 0.048757 seconds

and crontab appears to be setup correctly.

Although, the first time that I ran cli cron on this install, this was part of my output:

Adhoc task failed: core_course\task\course_delete_modules,Coding error detected, it must be fixed by a programmer: The course module 2 could not be deleted. #0 /var/www/html/moodle/lib/dml/moodle_database.php(1522): moodle_database->get_record_select('quiz', 'WHERE id = ?', Array, '*', 2)

...

... used 239 dbqueries
... used 0.48178696632385 seconds
Adhoc task complete: core_course\task\course_delete_modules
Cron script completed correctly
Cron completed at 16:23:04. Memory used 55.8MB.
Execution took 34.095514 seconds

That worried me a little after reading the conclusion of this dubiously related thread:

Moodle version:  3.6

Average of ratings: -
In reply to Bo Pierce

Re: Failing to create a new scheduled task

by Jean-Michel Védrine -

I think part of your problem is that your task don't have the correct namespace:

it should not be question_type_random\task;

but qtype_random\task

You seems to be confused between the path and the component name.

Note that I have not looked deeply at all your code or reviewed it, but that first mistake should be corrected before you go further.

In reply to Jean-Michel Védrine

Re: Failing to create a new scheduled task

by Jean-Michel Védrine -

Also I think that you need to increase the version of the plugin qtype_random in question/type/random/version.php when you add a new scheduled task.

In reply to Bo Pierce

Re: Failing to create a new scheduled task

by Jean-Michel Védrine -

I attach a zip file containing your files corrected and the required changes to the lang and version files of the qtype_random plugin.

I have verified that the scheduled task is correctly listed in the site Administration and that it runs with no problem, but I have not verified that it does what it says because I don't have any unused random question.


In reply to Jean-Michel Védrine

Re: Failing to create a new scheduled task

by Bo Pierce -

I have fixed a bug in my solution,
begun testing the scheduled task,
reported my testing steps and results,
and re-compressed the directory to attach to this message.

In reply to Bo Pierce

Re: Failing to create a new scheduled task

by Vlad Bogomolov -

I have a lot of questions (9000000), I added "LIMIT".

In reply to Vlad Bogomolov

Re: Failing to create a new scheduled task

by Jerry Lau -

Hi Vlad.

Where did you add the limit and how? which file ?

thanks