Skip to content

Commit

Permalink
MDL-73846 assignfeedback_editpdf: Add limit for convert_submissions task
Browse files Browse the repository at this point in the history
  • Loading branch information
golenkovm committed Mar 8, 2022
1 parent 646c691 commit 3679e8d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Expand Up @@ -54,7 +54,12 @@ public function execute() {

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();

Expand Down
37 changes: 37 additions & 0 deletions mod/assign/feedback/editpdf/tests/editpdf_test.php
Expand Up @@ -527,4 +527,41 @@ public function test_is_feedback_modified() {
// 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'));
}
}

0 comments on commit 3679e8d

Please sign in to comment.