MDL-85262 tool_task: switch next run time comparison in renderer.

If a task is "due", then next run time should be considered "ASAP".
This commit is contained in:
Paul Holden
2025-05-13 22:13:12 +01:00
parent 9242f9619a
commit 4e1dd1d51f
4 changed files with 43 additions and 25 deletions
+1 -1
View File
@@ -287,7 +287,7 @@ class tool_task_renderer extends plugin_renderer_base {
$nextruntime = $task->get_next_run_time();
$due = $nextruntime < $now;
if ($task->get_attempts_available() > 0) {
$nextrun = $due ? userdate($nextruntime) : get_string('asap', 'tool_task');
$nextrun = $due ? get_string('asap', 'tool_task') : userdate($nextruntime);
} else {
$nextrun = get_string('never', 'admin');
}
@@ -0,0 +1,39 @@
@tool @tool_task @javascript
Feature: Manage adhoc task
In order to manage adhoc tasks
As an admin
I need to be able to view and delete adhoc tasks
Scenario Outline: View adhoc tasks next run time
Given the following "tool_task > adhoc tasks" exist:
| classname | seconds | hostname | pid | nextruntime |
| \core\task\asynchronous_backup_task | 0 | c69335460f7f | 1915 | <nextruntime> |
When I log in as "admin"
And I navigate to "Server > Tasks > Ad hoc tasks" in site administration
Then the following should exist in the "Ad hoc tasks" table:
| Component / Class name | Next run |
| asynchronous_backup_task | <nextruntimestr> |
And I click on "asynchronous_backup_task" "link" in the "Ad hoc tasks" "table"
And the following should exist in the "\core\task\asynchronous_backup_task Ad hoc tasks" table:
| Next run |
| <nextruntimestr> |
Examples:
| nextruntime | nextruntimestr |
| ##yesterday## | ASAP |
| ##tomorrow noon## | ##tomorrow noon##%A, %d %B %Y, %I:%M## |
Scenario: Delete an existing adhoc task
Given I log in as "admin"
And the following "tool_task > adhoc tasks" exist:
| classname | seconds | hostname | pid |
| \core\task\asynchronous_backup_task | 7201 | c69335460f7f | 1915 |
| \core\task\asynchronous_restore_task | 172800 | c69335460f7f | 1916 |
And I navigate to "Server > Tasks > Ad hoc tasks" in site administration
Then "asynchronous_backup_task" "table_row" should exist
And "asynchronous_restore_task" "table_row" should exist
And I follow "asynchronous_backup_task"
When I follow "Delete"
And I click on "Delete" "button" in the ".modal-dialog" "css_element"
Then I navigate to "Server > Tasks > Ad hoc tasks" in site administration
And "asynchronous_backup_task" "table_row" should not exist
And "asynchronous_restore_task" "table_row" should exist
@@ -1,21 +0,0 @@
@tool @tool_task @javascript
Feature: Delete an adhoc task
In order to manage adhoc tasks
As an admin
I need to be able to delete adhoc tasks
Scenario: Delete an existing adhoc task
Given I log in as "admin"
And the following "tool_task > adhoc tasks" exist:
| classname | seconds | hostname | pid |
| \core\task\asynchronous_backup_task | 7201 | c69335460f7f | 1915 |
| \core\task\asynchronous_restore_task | 172800 | c69335460f7f | 1916 |
And I navigate to "Server > Tasks > Ad hoc tasks" in site administration
Then "asynchronous_backup_task" "table_row" should exist
And "asynchronous_restore_task" "table_row" should exist
And I follow "asynchronous_backup_task"
When I follow "Delete"
And I click on "Delete" "button" in the ".modal-dialog" "css_element"
Then I navigate to "Server > Tasks > Ad hoc tasks" in site administration
And "asynchronous_backup_task" "table_row" should not exist
And "asynchronous_restore_task" "table_row" should exist
+3 -3
View File
@@ -43,7 +43,7 @@ class tool_task_generator extends testing_module_generator {
global $DB;
$conditions = ['classname' => $data['classname']];
$record = $DB->get_record('task_scheduled', $conditions, '*', MUST_EXIST);
$record->timestarted = time() - $data['seconds'];
$record->timestarted = $data['seconds'] > 0 ? time() - $data['seconds'] : 0;
$record->hostname = $data['hostname'];
$record->pid = $data['pid'];
$DB->update_record('task_scheduled', $record);
@@ -59,8 +59,8 @@ class tool_task_generator extends testing_module_generator {
global $DB;
$adhoctask = (object)[
'classname' => $data['classname'],
'nextruntime' => 0,
'timestarted' => time() - $data['seconds'],
'nextruntime' => $data['nextruntime'] ?? 0,
'timestarted' => $data['seconds'] > 0 ? time() - $data['seconds'] : 0,
'hostname' => $data['hostname'],
'pid' => $data['pid'],
];