mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-34351 quiz cron: one broken overdue attempt should not kill cron
It seems that sometimes trying to process an overdue quiz attempt can throw an exception. In that case, we need to catch it and report it nicely, and then carry on processing the rest of the attempts, rather than just killing the whole of cron processing. Also, there may be garbage quiz attempts where the associated quiz or course has been deleted. Skip those too.
This commit is contained in:
parent
3294034b80
commit
c33d527833
1 changed files with 29 additions and 20 deletions
|
@ -57,6 +57,8 @@ class mod_quiz_overdue_attempt_updater {
|
|||
$count = 0;
|
||||
$quizcount = 0;
|
||||
foreach ($attemptstoprocess as $attempt) {
|
||||
try {
|
||||
|
||||
// If we have moved on to a different quiz, fetch the new data.
|
||||
if (!$quiz || $attempt->quiz != $quiz->id) {
|
||||
$quiz = $DB->get_record('quiz', array('id' => $attempt->quiz), '*', MUST_EXIST);
|
||||
|
@ -78,6 +80,13 @@ class mod_quiz_overdue_attempt_updater {
|
|||
$attemptobj = new quiz_attempt($attempt, $quizforuser, $cm, $course);
|
||||
$attemptobj->handle_if_time_expired($timenow, false);
|
||||
$count += 1;
|
||||
|
||||
} catch (moodle_exception $e) {
|
||||
// If an error occurs while processing one attempt, don't let that kill cron.
|
||||
mtrace("Error while processing attempt {$attempt->id} at {$attempt->quiz} quiz:");
|
||||
mtrace($e->getMessage());
|
||||
mtrace($e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
$attemptstoprocess->close();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue