Skip to content

Commit

Permalink
feat: Limit SetupCheck computing time to 5 seconds
Browse files Browse the repository at this point in the history
In case of early stop, it will show in the output since when was the
number of errors or warnings counted.

Also added time to the output in case the date is today.

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Mar 11, 2024
1 parent 0be413d commit 7af84d9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/SetupChecks/LogErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function run(): SetupResult {
self::LEVEL_FATAL => 0,
];
$limit = new \DateTime('7 days ago');
$startTime = microtime(true);
foreach ($logIterator as $logItem) {
if (!isset($logItem['time'])) {
continue;
Expand All @@ -70,16 +71,23 @@ public function run(): SetupResult {
break;
}
$count[$logItem['level']]++;
if (microtime(true) > $startTime + 5) {
echo $logItem['time']."\n";
echo $this->dateFormatter->formatDate($time)."\n";
echo $this->dateFormatter->formatDateTime($time)."\n";
$limit = $time;
break;
}
}
if (array_sum($count) === 0) {
return SetupResult::success($this->l10n->t('No errors in the logs since %s', $this->dateFormatter->formatDate($limit)));
return SetupResult::success($this->l10n->t('No errors in the logs since %s', $this->dateFormatter->formatDateTime($limit)));
} elseif ($count[self::LEVEL_ERROR] + $count[self::LEVEL_FATAL] > 0) {
return SetupResult::warning(
$this->l10n->n(
'%n error in the logs since %s',
'%n errors in the logs since %s',
$count[self::LEVEL_ERROR] + $count[self::LEVEL_FATAL],
[$this->dateFormatter->formatDate($limit)],
[$this->dateFormatter->formatDateTime($limit)],
)
);
} else {
Expand All @@ -88,7 +96,7 @@ public function run(): SetupResult {
'%n warning in the logs since %s',
'%n warnings in the logs since %s'.json_encode($count),
$count[self::LEVEL_WARNING],
[$this->dateFormatter->formatDate($limit)],
[$this->dateFormatter->formatDateTime($limit)],
)
);
}
Expand Down

0 comments on commit 7af84d9

Please sign in to comment.