mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Merge branch 'MDL-75247-master' of https://github.com/cameron1729/moodle
This commit is contained in:
commit
01f72edd49
@ -17,6 +17,7 @@
|
||||
namespace assignfeedback_editpdf\task;
|
||||
|
||||
use core\task\adhoc_task;
|
||||
use core\task\manager;
|
||||
use assignfeedback_editpdf\document_services;
|
||||
use assignfeedback_editpdf\combined_document;
|
||||
use context_module;
|
||||
@ -60,18 +61,58 @@ class convert_submission extends adhoc_task {
|
||||
}
|
||||
}
|
||||
|
||||
$conversionrequirespolling = false;
|
||||
foreach ($users as $userid) {
|
||||
mtrace('Converting submission for user id ' . $userid);
|
||||
$combineddocument = document_services::get_combined_pdf_for_attempt($assign, $userid, $data->submissionattempt);
|
||||
$status = $combineddocument->get_status();
|
||||
if ($status == combined_document::STATUS_COMPLETE) {
|
||||
document_services::get_page_images_for_attempt($assign, $userid, $data->submissionattempt, false);
|
||||
document_services::get_page_images_for_attempt($assign, $userid, $data->submissionattempt, true);
|
||||
|
||||
mtrace('The document has been successfully converted');
|
||||
} else {
|
||||
throw new \coding_exception('Document conversion completed with status ' . $status);
|
||||
// Note: Before MDL-71468, the scheduled task version of this
|
||||
// task would stop attempting to poll the conversion after a
|
||||
// configured number of attempts were made to poll it, see:
|
||||
//
|
||||
// mod/assign/feedback/editpdf/classes/task/convert_submissions.php@MOODLE_400_STABLE
|
||||
//
|
||||
// This means that currently this adhoc task, if it fails, will retry forever. But
|
||||
// the fail-delay mechanism will ensure that it eventually only tries once per day.
|
||||
//
|
||||
// See MDL-75457 for details on re-implementing the conversionattemptlimit.
|
||||
//
|
||||
// Also note: This code must not be in a try/catch - an exception needs to be thrown to
|
||||
// allow the task API to mark the task as failed and update its faildelay. Using
|
||||
// manager::adhoc_task_failed in the catch block will not work, as the task API
|
||||
// will later assume the task completed successfully (as no exception was thrown) and
|
||||
// complete it (removing it from the adhoc task queue).
|
||||
$combineddocument = document_services::get_combined_pdf_for_attempt($assign, $userid, $data->submissionattempt);
|
||||
switch ($combineddocument->get_status()) {
|
||||
case combined_document::STATUS_READY:
|
||||
case combined_document::STATUS_READY_PARTIAL:
|
||||
case combined_document::STATUS_PENDING_INPUT:
|
||||
// The document has not been converted yet or is somehow still ready.
|
||||
$conversionrequirespolling = true;
|
||||
continue 2;
|
||||
case combined_document::STATUS_FAILED:
|
||||
// Although STATUS_FAILED indicates a "permanent error" it should be possible
|
||||
// in some cases to fix the underlying problem, allowing the conversion to
|
||||
// complete. So we throw an exception here, allowing the adhoc task to retry.
|
||||
//
|
||||
// Currently this can result in the task trying indefinitely (although it will
|
||||
// settle on trying once per day due to the faildelay exponential backoff)
|
||||
// however once the conversionattepmtlimit is re-implemented in MDL-75457 the
|
||||
// task will eventually get dropped.
|
||||
throw new \moodle_exception('documentcombinationfailed');
|
||||
}
|
||||
|
||||
document_services::get_page_images_for_attempt($assign, $userid, $data->submissionattempt, false);
|
||||
document_services::get_page_images_for_attempt($assign, $userid, $data->submissionattempt, true);
|
||||
}
|
||||
|
||||
if ($conversionrequirespolling) {
|
||||
mtrace('Conversion still in progress. Requeueing self to check again.');
|
||||
$task = new self;
|
||||
$task->set_custom_data($data);
|
||||
$task->set_next_run_time(time() + MINSECS);
|
||||
manager::queue_adhoc_task($task);
|
||||
} else {
|
||||
mtrace('The document has been successfully converted');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user