Merge branch 'MDL-74775-403' of https://github.com/HuongNV13/moodle into MOODLE_403_STABLE
This commit is contained in:
@@ -229,6 +229,9 @@ class manager {
|
||||
$record->nextruntime = time() - 1;
|
||||
}
|
||||
|
||||
// Set the time the task was created.
|
||||
$record->timecreated = time();
|
||||
|
||||
// Check if the same task is already scheduled.
|
||||
if ($checkforexisting && self::task_is_scheduled($task)) {
|
||||
return false;
|
||||
@@ -307,7 +310,6 @@ class manager {
|
||||
$record->faildelay = $task->get_fail_delay();
|
||||
$record->customdata = $task->get_custom_data_as_string();
|
||||
$record->userid = $task->get_userid();
|
||||
$record->timecreated = time();
|
||||
$record->timestarted = $task->get_timestarted();
|
||||
$record->hostname = $task->get_hostname();
|
||||
$record->pid = $task->get_pid();
|
||||
|
||||
@@ -644,4 +644,54 @@ class adhoc_task_test extends \advanced_testcase {
|
||||
$this->expectExceptionMessage('error/invalidtaskid');
|
||||
manager::get_adhoc_task($taskid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test adhoc task failure will retain the time information.
|
||||
*
|
||||
* @covers ::queue_adhoc_task
|
||||
* @covers ::get_next_adhoc_task
|
||||
* @covers ::adhoc_task_failed
|
||||
*/
|
||||
public function test_adhoc_task_failed_will_retain_time_info(): void {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$now = time();
|
||||
// Create an adhoc task.
|
||||
$task = new adhoc_test_task();
|
||||
// Queue it.
|
||||
$taskid = manager::queue_adhoc_task(task: $task);
|
||||
|
||||
// Update the timecreated of the task to be older.
|
||||
$DB->set_field(
|
||||
table: 'task_adhoc',
|
||||
newfield: 'timecreated',
|
||||
newvalue: time() - DAYSECS,
|
||||
conditions: ['id' => $taskid],
|
||||
);
|
||||
|
||||
// Get the timecreated value before marking the task as failed.
|
||||
$timecreatedbefore = $DB->get_field(
|
||||
table: 'task_adhoc',
|
||||
return: 'timecreated',
|
||||
conditions: ['id' => $taskid],
|
||||
);
|
||||
|
||||
// Get the task from the scheduler.
|
||||
$task = manager::get_next_adhoc_task(timestart: $now);
|
||||
// Execute the task.
|
||||
$task->execute();
|
||||
// Mark the task as failed.
|
||||
manager::adhoc_task_failed(task: $task);
|
||||
|
||||
// Get the timecreated value after marking the task as failed.
|
||||
$timecreatedafter = $DB->get_field(
|
||||
table: 'task_adhoc',
|
||||
return: 'timecreated',
|
||||
conditions: ['id' => $taskid],
|
||||
);
|
||||
|
||||
// The timecreated values should be the same.
|
||||
$this->assertEquals($timecreatedbefore, $timecreatedafter);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user