MDL-47480 tasks: Define order for getting tasks
This commit is contained in:
@@ -448,7 +448,8 @@ class manager {
|
||||
|
||||
$where = "(lastruntime IS NULL OR lastruntime < :timestart1)
|
||||
AND (nextruntime IS NULL OR nextruntime < :timestart2)
|
||||
AND disabled = 0";
|
||||
AND disabled = 0
|
||||
ORDER BY lastruntime, id ASC";
|
||||
$params = array('timestart1' => $timestart, 'timestart2' => $timestart);
|
||||
$records = $DB->get_records_select('task_scheduled', $where, $params);
|
||||
|
||||
|
||||
@@ -282,6 +282,33 @@ class core_scheduled_task_testcase extends advanced_testcase {
|
||||
// Should not get any task.
|
||||
$task = \core\task\manager::get_next_scheduled_task($now);
|
||||
$this->assertNull($task);
|
||||
|
||||
// Check ordering.
|
||||
$DB->delete_records('task_scheduled');
|
||||
$record->lastruntime = 2;
|
||||
$record->disabled = 0;
|
||||
$record->classname = '\core\task\scheduled_test_task';
|
||||
$DB->insert_record('task_scheduled', $record);
|
||||
|
||||
$record->lastruntime = 1;
|
||||
$record->classname = '\core\task\scheduled_test2_task';
|
||||
$DB->insert_record('task_scheduled', $record);
|
||||
|
||||
// Should get handed the second task.
|
||||
$task = \core\task\manager::get_next_scheduled_task($now);
|
||||
$this->assertInstanceOf('\core\task\scheduled_test2_task', $task);
|
||||
$task->execute();
|
||||
\core\task\manager::scheduled_task_complete($task);
|
||||
|
||||
// Should get handed the first task.
|
||||
$task = \core\task\manager::get_next_scheduled_task($now);
|
||||
$this->assertInstanceOf('\core\task\scheduled_test_task', $task);
|
||||
$task->execute();
|
||||
\core\task\manager::scheduled_task_complete($task);
|
||||
|
||||
// Should not get any task.
|
||||
$task = \core\task\manager::get_next_scheduled_task($now);
|
||||
$this->assertNull($task);
|
||||
}
|
||||
|
||||
public function test_get_broken_scheduled_task() {
|
||||
|
||||
Reference in New Issue
Block a user