MDL-73846 assignfeedback_editpdf: Add limit for convert_submissions task
This commit is contained in:
@@ -54,7 +54,12 @@ class convert_submissions extends scheduled_task {
|
||||
|
||||
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
||||
|
||||
$records = $DB->get_records('assignfeedback_editpdf_queue');
|
||||
// Conversion speed varies significantly and mostly depends on the documents content.
|
||||
// We don't want the task to get stuck forever trying to process the whole queue in one go,
|
||||
// so fetch 100 records only to make sure the task will be working for reasonable time.
|
||||
// With the task's default schedule, 100 records per run means the task is capable to process
|
||||
// 9600 conversions per day (100 * 4 * 24).
|
||||
$records = $DB->get_records('assignfeedback_editpdf_queue', [], '', '*', 0, 100);
|
||||
|
||||
$assignmentcache = array();
|
||||
|
||||
|
||||
@@ -527,4 +527,41 @@ class assignfeedback_editpdf_testcase extends advanced_testcase {
|
||||
// No modification.
|
||||
$this->assertFalse($plugin->is_feedback_modified($grade, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Convert submissions scheduled task limit.
|
||||
*
|
||||
* @covers \assignfeedback_editpdf\task\convert_submissions
|
||||
*/
|
||||
public function test_conversion_task_limit() {
|
||||
global $DB;
|
||||
$this->require_ghostscript();
|
||||
$this->resetAfterTest();
|
||||
cron_setup_user();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$assignopts = [
|
||||
'assignsubmission_file_enabled' => 1,
|
||||
'assignsubmission_file_maxfiles' => 1,
|
||||
'assignfeedback_editpdf_enabled' => 1,
|
||||
'assignsubmission_file_maxsizebytes' => 1000000,
|
||||
];
|
||||
$assign = $this->create_instance($course, $assignopts);
|
||||
|
||||
// Generate 110 submissions.
|
||||
for ($i = 0; $i < 110; $i++) {
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
$this->add_file_submission($student, $assign);
|
||||
}
|
||||
$this->assertEquals(110, $DB->count_records('assignfeedback_editpdf_queue'));
|
||||
|
||||
// Run the conversion task.
|
||||
$task = new \assignfeedback_editpdf\task\convert_submissions;
|
||||
ob_start();
|
||||
$task->execute();
|
||||
ob_end_clean();
|
||||
|
||||
// Confirm, that 100 records were processed and 10 were left for the next task run.
|
||||
$this->assertEquals(10, $DB->count_records('assignfeedback_editpdf_queue'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user