Skip to content

Commit

Permalink
MDL-70975 task: adhoctasks.php - queued ad hoc tasks report
Browse files Browse the repository at this point in the history
Similar to scheduled tasks report

core\task\manager::adhoc_task_from_record() now raises moodle_exception
  • Loading branch information
srdjan-catalyst committed Apr 5, 2023
1 parent 6d9aaa8 commit 8532307
Show file tree
Hide file tree
Showing 11 changed files with 755 additions and 38 deletions.
2 changes: 1 addition & 1 deletion admin/tasklogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

if (!empty($filter)) {
$report->set_filter_values([
'task_log:name_values' => $filter,
'task_log:name_values' => trim($filter, '\\'),
]);
}

Expand Down
60 changes: 60 additions & 0 deletions admin/tool/task/adhoctasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Ad hoc task list.
*
* @package tool_task
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');

admin_externalpage_setup('adhoctasks');

$failedonly = optional_param('failedonly', false, PARAM_BOOL);
$classname = optional_param('classname', null, PARAM_RAW);

$renderer = $PAGE->get_renderer('tool_task');

if ($classname) {
$pageurl = new moodle_url('/admin/tool/task/adhoctasks.php');
$PAGE->navbar->add(get_string('adhoctasks', 'tool_task'), $pageurl);
$PAGE->navbar->add($classname, $PAGE->url);

$tasks = core\task\manager::get_adhoc_tasks($classname, $failedonly);

echo $OUTPUT->header();

if (!get_config('core', 'cron_enabled')) {
echo $renderer->cron_disabled();
}

echo $renderer->adhoc_tasks_class_table($classname, $tasks, ['failedonly' => $failedonly]);
} else {
$summary = core\task\manager::get_adhoc_tasks_summary();

echo $OUTPUT->header();

if (!get_config('core', 'cron_enabled')) {
echo $renderer->cron_disabled();
}

echo $renderer->adhoc_tasks_summary_table($summary);
}
echo $OUTPUT->footer();
21 changes: 21 additions & 0 deletions admin/tool/task/lang/en/tool_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@

$string['adhoc'] = 'Ad hoc';
$string['adhoctaskid'] = 'Ad hoc task ID: {$a}';
$string['adhoctaskrun'] = 'Ad hoc task run initiated';
$string['adhoctasks'] = 'Ad hoc tasks';
$string['adhoctasksdue'] = 'Ad hoc tasks due';
$string['adhoctasksfailed'] = 'Ad hoc tasks failed';
$string['adhoctasksfuture'] = 'Future ad hoc tasks';
$string['adhoctasksrunning'] = 'Ad hoc tasks running';
$string['asap'] = 'ASAP';
$string['adhocempty'] = 'Ad hoc task queue is empty';
$string['adhocqueuesize'] = 'Ad hoc task queue has {$a} tasks';
$string['adhocqueueold'] = 'Oldest unprocessed task is {$a->age}, which is more than {$a->max}';
$string['backtoadhoctasks'] = 'Back to ad hoc tasks';
$string['backtoscheduledtasks'] = 'Back to scheduled tasks';
$string['blocking'] = 'Blocking';
$string['cannotfindthepathtothecli'] = 'Cannot find the path to the PHP CLI executable so task execution aborted. Set the \'Path to PHP CLI\' setting in Site administration / Server / System paths.';
Expand All @@ -51,31 +57,46 @@
$string['enablerunnow'] = 'Allow \'Run now\' for scheduled tasks';
$string['enablerunnow_desc'] = 'Allows administrators to run a single scheduled task immediately, rather than waiting for it to run as scheduled. The feature requires \'Path to PHP CLI\' (pathtophp) to be set in System paths. The task runs on the web server, so you may wish to disable this feature to avoid potential performance issues.';
$string['faildelay'] = 'Fail delay';
$string['failed'] = 'Failed';
$string['fromcomponent'] = 'From component: {$a}';
$string['hostname'] = 'Host name';
$string['lastcronstart'] = 'Time since last cron run: {$a}';
$string['lastruntime'] = 'Last run';
$string['lastupdated'] = 'Last updated {$a}.';
$string['nextruntime'] = 'Next run';
$string['noclassname'] = 'Class name not specified';
$string['notasks'] = 'No tasks to run';
$string['payload'] = 'Payload';
$string['pid'] = 'PID';
$string['plugindisabled'] = 'Plugin disabled';
$string['pluginname'] = 'Scheduled task configuration';
$string['resettasktodefaults'] = 'Reset task schedule to defaults';
$string['resettasktodefaults_help'] = 'This will discard any local changes and revert the schedule for this task back to its original settings.';
$string['run_adhoctasks'] = 'Run ad hoc tasks';
$string['runningalltasks'] = 'Running all tasks';
$string['runningfailedtasks'] = 'Running failed tasks';
$string['runningtasks'] = 'Tasks running now';
$string['runnow'] = 'Run now';
$string['runagain'] = 'Run again';
$string['runadhoc_confirm'] = 'Tasks will run on the web server and may take some time to complete.';
$string['runadhoc'] = 'Run ad hoc tasks now?';
$string['runnow_confirm'] = 'Are you sure you want to run this task \'{$a}\' now? The task will run on the web server and may take some time to complete.';
$string['runclassname'] = 'Run all';
$string['runclassnamefailedonly'] = 'Run all failed';
$string['runpattern'] = 'Run pattern';
$string['scheduled'] = 'Scheduled';
$string['scheduledtasks'] = 'Scheduled tasks';
$string['scheduledtaskchangesdisabled'] = 'Modifications to the list of scheduled tasks have been prevented in Moodle configuration';
$string['slowtask'] = 'Task has run for longer than {$a}';
$string['showall'] = 'Show all';
$string['showfailedonly'] = 'Show failed only';
$string['showsummary'] = 'Show ad hoc tasks summary';
$string['started'] = 'Started';
$string['taskage'] = 'Run time';
$string['taskdetails'] = 'Tasks running for more than {$a->time} (max {$a->maxtime}): {$a->count}';
$string['taskdisabled'] = 'Task disabled';
$string['taskfailures'] = '{$a} task(s) failing';
$string['taskid'] = 'Task ID';
$string['tasklogs'] = 'Task logs';
$string['tasknofailures'] = 'There are no tasks failing';
$string['taskrunningtime'] = 'Task has run for {$a}';
Expand Down
9 changes: 9 additions & 0 deletions admin/tool/task/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ function tool_task_status_checks() : array {
];
}

/**
* Function used to handle mtrace by outputting the text to normal browser window.
*
* @param string $message Message to output
* @param string $eol End of line character
*/
function tool_task_mtrace_wrapper(string $message, string $eol): void {
echo s($message . $eol);
}
Loading

0 comments on commit 8532307

Please sign in to comment.