[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Add consolidated logs feature to scheduler management
"SoftStart Code \(@softstartcode\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6907e37755101_2c4e617d01699b@gitlab-sidekiq-low-urgency-cpu-bound-v2-66dbb487d8-9xbf7.mail> |
SoftStart Code pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
8dc332f8 by Sandeep D at 2025-11-02T22:56:30+00:00
[ENH] Add consolidated logs feature to scheduler management
---
* [ENH] Add consolidated logs feature to scheduler management
* Introduced a new tab for consolidated logs in the scheduler admin interface.
* Implemented methods in SchedulersLib to fetch consolidated logs and count total runs.
* Enhanced the scheduler display to show last run status and stalled status for each task.
* Updated the template to display consolidated logs with pagination support.
* Add fallback display for deleted schedulers: '(Scheduler Deleted)'
See merge request tikiwiki/tiki!8921
- - - - -
3 changed files:
- lib/schedulerslib.php
- templates/tiki-admin_schedulers.tpl
- tiki-admin_schedulers.php
Changes:
=====================================
lib/schedulerslib.php
=====================================
@@ -104,6 +104,7 @@ class SchedulersLib extends TikiLib
if (! empty($runs) && $runs[0]['status'] == 'running') {
$runs[0]['output'] = SchedulerRunOutput::getTempLog($runs[0]['id']);
}
+
return $runs;
}
@@ -130,12 +131,50 @@ class SchedulersLib extends TikiLib
*
* @return int
*/
- public function countRuns($schedulerId)
+ public function countRuns($schedulerId = null)
{
$schedulersRunTable = $this->table('tiki_scheduler_run');
+ if ($schedulerId === null) {
+ return $schedulersRunTable->fetchCount([]);
+ }
return $schedulersRunTable->fetchCount(['scheduler_id' => $schedulerId]);
}
+ /**
+ * Get consolidated logs from all schedulers with scheduler names
+ *
+ * @param int $limit The number of runs to return
+ * @param int $offset The offset for pagination
+ *
+ * @return array An array with the consolidated scheduler runs found
+ */
+ public function getConsolidatedLogs($limit = 100, $offset = 0)
+ {
+ if (! is_numeric($limit)) {
+ $limit = 100;
+ }
+ if (! is_numeric($offset)) {
+ $offset = 0;
+ }
+
+ $query = "SELECT sr.*, sr.output as scheduler_output, s.name as scheduler_name
+ FROM `tiki_scheduler_run` sr
+ LEFT JOIN `tiki_scheduler` s ON sr.scheduler_id = s.id
+ ORDER BY sr.id DESC
+ LIMIT " . intval($offset) . ", " . intval($limit);
+
+ $runs = $this->fetchAll($query);
+
+ // Handle running tasks with temp log output
+ foreach ($runs as $key => $run) {
+ if ($run['status'] !== 'running') {
+ $runs[$key]['output'] = SchedulerRunOutput::getTempLog($run['id']);
+ }
+ }
+
+ return $runs;
+ }
+
/**
* Get scheduler last run status
*
@@ -149,6 +188,19 @@ class SchedulersLib extends TikiLib
return $schedulersRunTable->fetchOne('status', ['scheduler_id' => $scheduler_id], ['id' => 'DESC']);
}
+ /**
+ * Get scheduler last run stalled status from database
+ *
+ * @param int $scheduler_id The Scheduler Id
+ *
+ * @return bool|mixed
+ */
+ public function getStalled($scheduler_id)
+ {
+ $schedulersRunTable = $this->table('tiki_scheduler_run');
+ return $schedulersRunTable->fetchOne('stalled', ['scheduler_id' => $scheduler_id], ['id' => 'DESC']);
+ }
+
/**
* Get failed runs
*
=====================================
templates/tiki-admin_schedulers.tpl
=====================================
@@ -116,6 +116,10 @@
</th>
<th>
{*Reserved for stalled notices*}
+ Stalled
+ </th>
+ <th>
+ {tr}Last Run Status{/tr}
</th>
<th id="actions"></th>
</tr>
@@ -152,8 +156,23 @@
<input type="checkbox" {if $schedulers[scheduler].re_run}checked{/if} disabled>
</td>
<td class="scheduler_stalled">
- {if $schedulers[scheduler].stalled}
- <span class="label label-danger">{tr}Stalled{/tr}</span>
+ {if $schedulers[scheduler].last_run_stalled}
+ <span class="badge bg-danger">{tr}Yes{/tr}</span>
+ {else}
+ <span class="badge bg-secondary">{tr}No{/tr}</span>
+ {/if}
+ </td>
+ <td class="scheduler_last_run_status">
+ {if $schedulers[scheduler].last_run_status eq 'running'}
+ <span class="badge bg-warning">{tr}Running{/tr}</span>
+ {elseif $schedulers[scheduler].last_run_status eq 'failed'}
+ <span class="badge bg-danger">{tr}Failed{/tr}</span>
+ {elseif $schedulers[scheduler].last_run_status eq 'done'}
+ <span class="badge bg-success">{tr}Done{/tr}</span>
+ {elseif $schedulers[scheduler].stalled}
+ <span class="badge bg-danger">{tr}Stalled{/tr}</span>
+ {else}
+ <span class="text-muted">-</span>
{/if}
</td>
<td class="action">
@@ -508,6 +527,80 @@
</div>
{/tab}
{/if}
+
+{* ---------------------- Consolidated Logs Tab -------------------- *}
+<a id="tab5"></a>
+{if !isset($schedulerinfo.id)}
+{tab name="{tr}Logs{/tr}"}
+ <h2>{tr}Scheduler Run Logs{/tr}</h2>
+ <h3>{tr}Last {$numOfLogs} Logs{/tr}</h3>
+ <div id="admin_schedulers_logs-div">
+ <div class="{if $js}table-responsive {/if}ts-wrapperdiv">
+ <table class="table normal table-striped table-hover">
+ <thead>
+ <tr>
+ <th>ID</th>
+ <th>{tr}Name{/tr}</th>
+ <th>{tr}Start Time{/tr}</th>
+ <th>{tr}End Time{/tr}</th>
+ <th>{tr}Status{/tr}</th>
+ <th>{tr}Output{/tr}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {section name=run loop=$consolidatedLogs}
+ <tr>
+ <td>{$consolidatedLogs[run].id}</td>
+ <td>
+ {if $consolidatedLogs[run].scheduler_name}
+ {$consolidatedLogs[run].scheduler_name|escape}
+ {else}
+ <span class="text-muted fst-italic">{tr}Scheduler Deleted{/tr}</span>
+ {/if}
+ </td>
+ <td>
+ {$consolidatedLogs[run].start_time|tiki_short_datetime} ({$display_timezone})
+ {if $display_timezone ne 'UTC'}
+ <br>{$consolidatedLogs[run].start_time|tiki_short_datetime:'':'y':'UTC'} (UTC)
+ {/if}
+ </td>
+ <td>
+ {if $consolidatedLogs[run].end_time ne null}
+ {$consolidatedLogs[run].end_time|tiki_short_datetime} ({$display_timezone})
+ {if $display_timezone ne 'UTC'}
+ <br>{$consolidatedLogs[run].end_time|tiki_short_datetime:'':'y':'UTC'} (UTC)
+ {/if}
+ {/if}
+ </td>
+ <td>
+ {if $consolidatedLogs[run].status eq 'running'}
+ <span class="badge bg-warning">{tr}Running{/tr}</span>
+ {/if}
+ {if $consolidatedLogs[run].status eq 'failed'}
+ <span class="badge bg-danger">{tr}Failed{/tr}</span>
+ {/if}
+ {if $consolidatedLogs[run].status eq 'done'}
+ <span class="badge bg-success">{tr}Done{/tr}</span>
+ {/if}
+ </td>
+ <td>
+ {$consolidatedLogs[run].scheduler_output|nl2br}
+ </td>
+ </tr>
+ {sectionelse}
+ <tr>
+ <td colspan="6" class="text-center text-muted py-4">
+ {tr}No scheduler logs found{/tr}
+ </td>
+ </tr>
+ {/section}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ {pagination_links count=$consolidatedLogsCount step=$numrows offset=$offset}tiki-admin_schedulers.php?consolidated_logs=1{/pagination_links}
+{/tab}
+{/if}
{/tabset}
{jq}
=====================================
tiki-admin_schedulers.php
=====================================
@@ -23,6 +23,7 @@ $inputConfiguration = [
'offset' => 'digits', //get
'numrows' => 'digits', //post
'logs' => 'string', //post
+ 'consolidated_logs' => 'digits', //get
'add' => 'alpha', //get
'filter' => 'string', //get
'save' => 'alpha', //post
@@ -169,12 +170,16 @@ $auto_query_args = [
'scheduler',
'logs',
'filter',
+ 'consolidated_logs',
];
$schedLib = TikiLib::lib('scheduler');
$schedulerTasks = Scheduler_Item::getAvailableTasks();
$scheduler = 0;
+$tikilib = TikiLib::lib('tiki');
+$numOfLogs = $tikilib->get_preference('scheduler_keep_logs');
+
if ((isset($_POST['new_scheduler']) || (isset($_POST['editscheduler']) && isset($_POST['scheduler']))) && $access->checkCsrf()) {
// If scheduler saved, it redirects to the schedulers page, cleaning the add/edit scheduler form.
$schedulerinfo = saveScheduler();
@@ -194,23 +199,9 @@ if ((isset($_POST['new_scheduler']) || (isset($_POST['editscheduler']) && isset(
} else {
$scheduler = $_REQUEST['scheduler'];
$schedulerinfo['params'] = json_decode($schedulerinfo['params'], true);
+ $offset = empty($_REQUEST['offset']) ? 0 : $_REQUEST['offset'];
+ $numRows = empty($_REQUEST['numrows']) ? $maxRecords : $_REQUEST['numrows'];
- if (empty($_REQUEST['offset'])) {
- $offset = 0;
- } else {
- $offset = $_REQUEST['offset'];
- }
- $smarty->assign_by_ref('offset', $offset);
-
- if (empty($_REQUEST['numrows'])) {
- $numRows = $maxRecords;
- } else {
- $numRows = $_REQUEST['numrows'];
- }
- $smarty->assign_by_ref('numrows', $numRows);
-
- $tikilib = TikiLib::lib('tiki');
- $numOfLogs = $tikilib->get_preference('scheduler_keep_logs');
$schedulerRuns = $schedLib->get_scheduler_runs($scheduler, $numRows, $offset);
$runsCount = $schedLib->countRuns($scheduler);
@@ -219,7 +210,6 @@ if ((isset($_POST['new_scheduler']) || (isset($_POST['editscheduler']) && isset(
}
$smarty->assign_by_ref('count', $runsCount);
- $smarty->assign_by_ref('numOfLogs', $numOfLogs);
// Check if last run is still running and can be stopped.
if (
@@ -257,8 +247,28 @@ if ((isset($_POST['new_scheduler']) || (isset($_POST['editscheduler']) && isset(
}
}
$scheduler = 0;
+ $offset = empty($_REQUEST['offset']) ? 0 : $_REQUEST['offset'];
+ $numRows = empty($_REQUEST['numrows']) ? $maxRecords : $_REQUEST['numrows'];
+
+ // Fetch consolidated logs for the Logs tab (tabs use client-side navigation)
+ $consolidatedLogs = $schedLib->getConsolidatedLogs($numRows, $offset);
+ $consolidatedLogsCount = $schedLib->countRuns();
+ if ($consolidatedLogsCount > $numOfLogs && $numOfLogs > 0) {
+ $consolidatedLogsCount = $numOfLogs;
+ }
+ $smarty->assign_by_ref('consolidatedLogsCount', $consolidatedLogsCount);
+ $smarty->assign_by_ref('consolidatedLogs', $consolidatedLogs);
+
+ // Set tab to Logs tab when paginating through consolidated logs
+ if (isset($_REQUEST['consolidated_logs'])) {
+ $cookietab = '5';
+ }
}
+$smarty->assign_by_ref('numOfLogs', $numOfLogs);
+$smarty->assign_by_ref('offset', $offset);
+$smarty->assign_by_ref('numrows', $numRows);
+
$tasks = $schedLib->get_scheduler(null, null, ['run_only_once' => 0]);
$logger = new Tiki_Log('Webcron', \Psr\Log\LogLevel::ERROR);
@@ -271,6 +281,8 @@ foreach ($tasks as $key => $task) {
}
$tasks[$key]['stalled'] = $schedulerItem->isStalled();
+ $tasks[$key]['last_run_status'] = $schedLib->get_run_status($task['id']);
+ $tasks[$key]['last_run_stalled'] = $schedLib->getStalled($task['id']);
if ($tasks[$key]['stalled']) {
$stalledTasksCount++;
}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/8dc332f86861dd061cc313eb935a5bc7bbeb78a6
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/8dc332f86861dd061cc313eb935a5bc7bbeb78a6
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs