SSR module: live progress bar for cache warming

The Cache warming row of the VITEC SSR module now shows a Bootstrap progress bar with a running counter instead of asking for a reload. New ajax route vitec_ssr_health (SsrController::healthJson) returns the node /__health JSON; ssr-warm-progress.js polls it every 2 s while a warm run is active and every 15 s otherwise (pauses in background tabs) and also refreshes the Cache: N pages / M MB line. The health fetch moved into SsrController::fetchHealth, shared by indexAction and the ajax route; its error text is English now. Verified live in the backend: bar, counter and cache line advance during a run.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
orascheandClaude Fable 5.1 committed 2026-11-10 19:40:46 +01:00
1 parent f4f18e913a
commit da2ca2690d
4 files changed
+136 -26

No files matched your search

@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -36,6 +37,7 @@ final class SsrController
private readonly ConnectionPool $connectionPool,
private readonly FlashMessageService $flashMessageService,
private readonly UriBuilder $uriBuilder,
private readonly PageRenderer $pageRenderer,
) {}
public function indexAction(ServerRequestInterface $request): ResponseInterface
@@ -43,29 +45,8 @@ final class SsrController
$view = $this->moduleTemplateFactory->create($request);
$view->setTitle('VITEC SSR');
$health = null;
$healthError = '';
$endpoint = $this->purgeService->getHealthEndpoint();
if ($endpoint === '') {
$healthError = 'var/vitec-ssr-purge.env fehlt oder ist unvollständig.';
} else {
$start = microtime(true);
try {
$response = $this->requestFactory->request($endpoint, 'GET', [
'timeout' => 3, 'connect_timeout' => 2, 'http_errors' => false,
]);
if ($response->getStatusCode() === 200) {
$health = json_decode((string)$response->getBody(), true) ?: null;
if ($health !== null) {
$health['responseMs'] = (int)round((microtime(true) - $start) * 1000);
}
} else {
$healthError = 'HTTP ' . $response->getStatusCode();
}
} catch (\Throwable $e) {
$healthError = $e->getMessage();
}
}
[$health, $healthError] = $this->fetchHealth();
$this->pageRenderer->loadJavaScriptModule('@evomedien/vitec/ssr-warm-progress.js');
$view->assignMultiple([
'flagOn' => file_exists(Environment::getVarPath() . '/vitec-ssr-on.flag'),
@@ -186,6 +167,44 @@ final class SsrController
]);
}
/**
* GET /__health of the SSR node. Returns [health array|null, error string].
*/
private function fetchHealth(): array
{
$endpoint = $this->purgeService->getHealthEndpoint();
if ($endpoint === '') {
return [null, 'var/vitec-ssr-purge.env missing or incomplete.'];
}
$start = microtime(true);
try {
$response = $this->requestFactory->request($endpoint, 'GET', [
'timeout' => 3, 'connect_timeout' => 2, 'http_errors' => false,
]);
if ($response->getStatusCode() !== 200) {
return [null, 'HTTP ' . $response->getStatusCode()];
}
$health = json_decode((string)$response->getBody(), true) ?: null;
if ($health === null) {
return [null, 'invalid JSON from /__health'];
}
$health['responseMs'] = (int)round((microtime(true) - $start) * 1000);
return [$health, ''];
} catch (\Throwable $e) {
return [null, $e->getMessage()];
}
}
/**
* Ajax route vitec_ssr_health: live status for the module's
* "Cache warming" progress bar (ssr-warm-progress.js polls it).
*/
public function healthJson(ServerRequestInterface $request): ResponseInterface
{
[$health, $error] = $this->fetchHealth();
return new JsonResponse(['health' => $health, 'error' => $error]);
}
private function rows(string $table, int $limit): array
{
try {