Problem in Cron Job

Problem in Cron Job

by Pawan Pandey -
Number of replies: 6

Hi There!

We are using,

Moodle : 3.5.9

PHP: 7.0.33

Actually we have perform migration from Moodle 3.4+ to Moodle 3.5.9. Now whenever we are trying to run

cron job i.e php admin/cli/cron.php. We are experiencing an error, which abruptly end cron job in middle.

We read somewhere that from moodle2.7+, if any issue in task within cron job, moodle leave particular task and continue to next. Following is the output of cron job.


Server Time: Tue, 03 Dec 2019 16:45:52 +0530
Execute scheduled task: Legacy cron processing for plugins (core\task\legacy_plugin_cron_task)
... started 16:45:53. Current memory use 15.4MB.
Running auth crons if required...
Running enrol crons if required...
Running cron for enrol_notificationeabc...
Starting activity modules
Processing module function assign_cron ...
... used 12 dbqueries
... used 4.0297000408173 seconds
done.
Processing module function chat_cron ...
... used 5 dbqueries
... used 0.35854697227478 seconds
done.
Processing module function quiz_cron ...

  Looking for quiz overdue quiz attempts...
!!! Exception - Argument 2 passed to has_capability() must be an instance of context, null given, called in [dirroot]\mod\quiz\attemptlib.php on line
 315 !!!

Average of ratings: -
In reply to Pawan Pandey

Re: Problem in Cron Job

by Benjamin Ellis -
Picture of Particularly helpful Moodlers
Do you have a 3rd party activity modules installed? On upgrading it is always a good idea to exclude any 3rd party plugins and then re-introduce them after the upgrade.
In reply to Benjamin Ellis

Re: Problem in Cron Job

by Pawan Pandey -

Thanks for reply!!

Actually what you told is something new for me i.e remove external plugins before up-gradation.

But if we closely look the last line of cron, it is related to quiz and we dont have any external plugin for quiz based activitiesBut we utilized quiz activities in lot of courses. 

Is there any possibility that it is happening in corruption of quiz related data in database ?? And if yes how we can rectify it or any further information which i can provide so that it can help you to assist in resolving this issue.


Thanks!

In reply to Pawan Pandey

Re: Problem in Cron Job

by Dominique Palumbo -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi,

this is the code. So the context is null for some reason.
has_capability('mod/quiz:ignoretimelimits', $this->context, null, false));

Maybee you can had in the code some traces to know the course that cause problem and the quiz.

Like
mtrace ('Tintin - courseid : ' . $course->id );
mtrace ('Tintin - quizid : ' . $quiz->id,);

Tintin is just to find it quickly in log...
I think that the good place to put it is in the function create() of the file
\mod\quiz\attemptlib.php

between these two lines :
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id, false, MUST_EXIST);

I hope it's not just.... stupid.

Sometime record is missing for some reasons...

Dominique.
Average of ratings: Useful (1)
In reply to Dominique Palumbo

Re: Problem in Cron Job

by Pawan Pandey -
Sorry for delayed response, I was able to identify the course by putting logger in code. But I dont know how to resolve this issues, as i dont have strong understanding about Moodle Context. And regarding the function create() in attemptlib.php, i put logger there, but it didnt work. Can you tell how we can fix this ??


Thanks
In reply to Pawan Pandey

Re: Problem in Cron Job

by Benjamin Ellis -
Picture of Particularly helpful Moodlers

The problem you have is that $this->context in mod/quiz/attemptlib.php is null as Dominique has mentioned.  The context for the class is set in the __construct() function based on the course module but may not be set if not required.   It may be worth adding some trace code in that function as well as the create() function.  The issue suggests to me a Quiz or Quiz attempt record that does not relate back to a course module.  I would check my quiz database records 1st.  

At the risk of telling you something you know already, if you are going to add debugging to core files, I suggest you backup the file first so you can restore it once you have determined what the issue is. 

In reply to Benjamin Ellis

Re: Problem in Cron Job

by Pawan Pandey -
Thanks for reply..
Actually we have run some cli admin commands like,

Fix orphaned question categories
--------------------------------------
admin/cli/fix_orphaned_question_categories.php --fix

Fix course/module sequences
-----------------------------------
php admin/cli/fix_course_sequence.php -c=* --fix

After this we are running cron.

Does the above command like can create a problem which justify your statement "The issue suggests to me a Quiz or Quiz attempt record that does not relate back to a course module."

Thanks for tips on backup, we are using git checkout -- * to undo changes.
Average of ratings: Useful (1)