-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Visualize rendering process, see #216
- Loading branch information
1 parent
a59ae80
commit 21c2357
Showing
13 changed files
with
348 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tpwd\KeSearch\Controller; | ||
|
||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Tpwd\KeSearch\Service\IndexerStatusService; | ||
use Tpwd\KeSearch\Utility\TimeUtility; | ||
|
||
class IndexerStatusController | ||
{ | ||
private ResponseFactoryInterface $responseFactory; | ||
private IndexerStatusService $indexerStatusService; | ||
|
||
public function __construct(ResponseFactoryInterface $responseFactory, IndexerStatusService $indexerStatusService) { | ||
$this->responseFactory = $responseFactory; | ||
$this->indexerStatusService = $indexerStatusService; | ||
} | ||
|
||
public function getStatusAction(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
$isRunning = $this->indexerStatusService->isRunning(); | ||
$indexerStatus = []; | ||
$html = 'Indexer is idle.'; | ||
|
||
if ($isRunning) { | ||
$indexerStartTime = $this->indexerStatusService->getIndexerStartTime(); | ||
$indexerStatus = $this->indexerStatusService->getIndexerStatus(); | ||
$html = 'Indexer is running since ' . TimeUtility::getRunningTimeHumanReadable($indexerStartTime) . '.'; | ||
if ($indexerStatus['indexers'] ?? false) { | ||
$html .= '<br /><br /><strong>Indexers:</strong><br />'; | ||
foreach ($indexerStatus['indexers'] as $singleIndexerStatus) { | ||
$statusLine = htmlspecialchars($singleIndexerStatus['statusText'], ENT_QUOTES, 'UTF-8') . '<br />'; | ||
if ($singleIndexerStatus['status'] == $this->indexerStatusService::INDEXER_STATUS_RUNNING) { | ||
$statusLine = '<strong>' . $statusLine . '</strong>'; | ||
} | ||
$html .= $statusLine; | ||
} | ||
} | ||
} | ||
|
||
$result = [ | ||
'running' => $isRunning, | ||
'indexers' => $indexerStatus['indexers'] ?? [], | ||
'html' => $html, | ||
]; | ||
|
||
$response = $this->responseFactory->createResponse() | ||
->withHeader('Content-Type', 'application/json; charset=utf-8'); | ||
$response->getBody()->write( | ||
json_encode($result, JSON_THROW_ON_ERROR), | ||
); | ||
|
||
return $response; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.