@@ -33,40 +33,40 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | class DefaultController extends AbstractController { |
| 35 | 35 | |
| 36 | - private CachedTenantContextInterface $tenantContext; |
|
| 37 | - private MetaFactoryInterface $metaFactory; |
|
| 38 | - private Context $templateEngineContext; |
|
| 39 | - private RouteFactoryInterface $routeFactory; |
|
| 40 | - |
|
| 41 | - public function __construct( |
|
| 42 | - CachedTenantContextInterface $tenantContext, |
|
| 43 | - MetaFactoryInterface $metaFactory, |
|
| 44 | - Context $templateEngineContext, |
|
| 45 | - RouteFactoryInterface $routeFactory |
|
| 46 | - ) { |
|
| 36 | + private CachedTenantContextInterface $tenantContext; |
|
| 37 | + private MetaFactoryInterface $metaFactory; |
|
| 38 | + private Context $templateEngineContext; |
|
| 39 | + private RouteFactoryInterface $routeFactory; |
|
| 40 | + |
|
| 41 | + public function __construct( |
|
| 42 | + CachedTenantContextInterface $tenantContext, |
|
| 43 | + MetaFactoryInterface $metaFactory, |
|
| 44 | + Context $templateEngineContext, |
|
| 45 | + RouteFactoryInterface $routeFactory |
|
| 46 | + ) { |
|
| 47 | 47 | $this->tenantContext = $tenantContext; |
| 48 | 48 | $this->metaFactory = $metaFactory; |
| 49 | 49 | $this->templateEngineContext = $templateEngineContext; |
| 50 | 50 | $this->routeFactory = $routeFactory; |
| 51 | - } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @Route("/", methods={"GET","POST"}, name="homepage") |
|
| 55 | - */ |
|
| 56 | - public function indexAction(Request $request): Response { |
|
| 53 | + /** |
|
| 54 | + * @Route("/", methods={"GET","POST"}, name="homepage") |
|
| 55 | + */ |
|
| 56 | + public function indexAction(Request $request): Response { |
|
| 57 | 57 | /** @var TenantInterface $currentTenant */ |
| 58 | 58 | $currentTenant = $this->tenantContext->getTenant(); |
| 59 | 59 | $route = $currentTenant->getHomepage(); |
| 60 | 60 | |
| 61 | 61 | if (null === $route) { |
| 62 | - /** @var RouteInterface $route */ |
|
| 63 | - $route = $this->routeFactory->create(); |
|
| 64 | - $route->setStaticPrefix('/'); |
|
| 65 | - $route->setName('Homepage'); |
|
| 66 | - $route->setType('content'); |
|
| 67 | - $route->setTemplateName('index.html.twig'); |
|
| 68 | - $route->setCacheTimeInSeconds(360); |
|
| 69 | - $request->attributes->set(DynamicRouter::ROUTE_KEY, $route); |
|
| 62 | + /** @var RouteInterface $route */ |
|
| 63 | + $route = $this->routeFactory->create(); |
|
| 64 | + $route->setStaticPrefix('/'); |
|
| 65 | + $route->setName('Homepage'); |
|
| 66 | + $route->setType('content'); |
|
| 67 | + $route->setTemplateName('index.html.twig'); |
|
| 68 | + $route->setCacheTimeInSeconds(360); |
|
| 69 | + $request->attributes->set(DynamicRouter::ROUTE_KEY, $route); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $this->templateEngineContext->setCurrentPage($this->metaFactory->create($route)); |
@@ -75,133 +75,133 @@ discard block |
||
| 75 | 75 | $response->headers->set('Content-Type', 'text/html; charset=UTF-8'); |
| 76 | 76 | |
| 77 | 77 | return $this->render('index.html.twig', [], $response); |
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @Route("/api/system/health", methods={"GET"}, name="system_health") |
|
| 82 | - */ |
|
| 83 | - public function healthCheck( |
|
| 84 | - Connection $connection, |
|
| 85 | - ElasticaClient $elasticaClient, |
|
| 86 | - AdapterInterface $cachePool |
|
| 87 | - ): JsonResponse { |
|
| 88 | - $status = [ |
|
| 89 | - 'application_name' => 'Publisher', |
|
| 90 | - 'postgres' => 'red', |
|
| 91 | - 'elasticsearch' => 'red', |
|
| 92 | - 'memcached' => 'red', |
|
| 93 | - 'rabbitmq' => 'red', |
|
| 94 | - 'supervisor' => 'red', |
|
| 95 | - ]; |
|
| 96 | - |
|
| 97 | - // Check PostgreSQL |
|
| 98 | - try { |
|
| 99 | - $connection->connect(); |
|
| 100 | - if ($connection->isConnected()) { |
|
| 101 | - $status['postgres'] = 'green'; |
|
| 102 | - } |
|
| 103 | - } catch (\Throwable $e) { |
|
| 104 | - // Log error for debugging |
|
| 105 | - error_log('PostgreSQL health check failed: ' . $e->getMessage()); |
|
| 106 | - $status['postgres'] = 'red'; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // Check Elasticsearch |
|
| 110 | - try { |
|
| 111 | - $elasticaClient->getStatus(); |
|
| 112 | - $status['elasticsearch'] = 'green'; |
|
| 113 | - } catch (\Throwable $e) { |
|
| 114 | - // Log error for debugging |
|
| 115 | - error_log('Elasticsearch health check failed: ' . $e->getMessage()); |
|
| 116 | - $status['elasticsearch'] = 'red'; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Check Memcached (Symfony Cache) |
|
| 120 | - try { |
|
| 121 | - $cacheKey = 'health_check_' . uniqid(); |
|
| 122 | - $cacheItem = $cachePool->getItem($cacheKey); |
|
| 123 | - $cacheItem->set('ok'); |
|
| 124 | - $cachePool->save($cacheItem); |
|
| 125 | - $cachePool->deleteItem($cacheKey); |
|
| 126 | - $status['memcached'] = 'green'; |
|
| 127 | - } catch (\Throwable $e) { |
|
| 128 | - // Log error for debugging |
|
| 129 | - error_log('Memcached health check failed: ' . $e->getMessage()); |
|
| 130 | - $status['memcached'] = 'red'; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // Check RabbitMQ using php-amqp extension |
|
| 134 | - try { |
|
| 135 | - $amqp = new \AMQPConnection([ |
|
| 136 | - 'host' => $_ENV['RABBIT_MQ_HOST'] ?? 'localhost', |
|
| 137 | - 'port' => (int)($_ENV['RABBIT_MQ_PORT'] ?? 5672), |
|
| 138 | - 'login' => $_ENV['RABBIT_MQ_USER'] ?? 'guest', |
|
| 139 | - 'password' => $_ENV['RABBIT_MQ_PASSWORD'] ?? 'guest', |
|
| 140 | - 'vhost' => $_ENV['RABBIT_MQ_VHOST'] ?? '/', |
|
| 141 | - ]); |
|
| 142 | - $amqp->connect(); |
|
| 143 | - if ($amqp->isConnected()) { |
|
| 144 | - $status['rabbitmq'] = 'green'; |
|
| 145 | - } |
|
| 146 | - } catch (\Throwable $e) { |
|
| 147 | - // Log error for debugging |
|
| 148 | - error_log('RabbitMQ health check failed: ' . $e->getMessage()); |
|
| 149 | - $status['rabbitmq'] = 'red'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Check Supervisor processes |
|
| 153 | - try { |
|
| 154 | - $process = new \Symfony\Component\Process\Process(['supervisorctl', 'status', 'messenger-consume:*']); |
|
| 155 | - $process->setTimeout(10); |
|
| 156 | - $process->run(); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @Route("/api/system/health", methods={"GET"}, name="system_health") |
|
| 82 | + */ |
|
| 83 | + public function healthCheck( |
|
| 84 | + Connection $connection, |
|
| 85 | + ElasticaClient $elasticaClient, |
|
| 86 | + AdapterInterface $cachePool |
|
| 87 | + ): JsonResponse { |
|
| 88 | + $status = [ |
|
| 89 | + 'application_name' => 'Publisher', |
|
| 90 | + 'postgres' => 'red', |
|
| 91 | + 'elasticsearch' => 'red', |
|
| 92 | + 'memcached' => 'red', |
|
| 93 | + 'rabbitmq' => 'red', |
|
| 94 | + 'supervisor' => 'red', |
|
| 95 | + ]; |
|
| 96 | + |
|
| 97 | + // Check PostgreSQL |
|
| 98 | + try { |
|
| 99 | + $connection->connect(); |
|
| 100 | + if ($connection->isConnected()) { |
|
| 101 | + $status['postgres'] = 'green'; |
|
| 102 | + } |
|
| 103 | + } catch (\Throwable $e) { |
|
| 104 | + // Log error for debugging |
|
| 105 | + error_log('PostgreSQL health check failed: ' . $e->getMessage()); |
|
| 106 | + $status['postgres'] = 'red'; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Check Elasticsearch |
|
| 110 | + try { |
|
| 111 | + $elasticaClient->getStatus(); |
|
| 112 | + $status['elasticsearch'] = 'green'; |
|
| 113 | + } catch (\Throwable $e) { |
|
| 114 | + // Log error for debugging |
|
| 115 | + error_log('Elasticsearch health check failed: ' . $e->getMessage()); |
|
| 116 | + $status['elasticsearch'] = 'red'; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Check Memcached (Symfony Cache) |
|
| 120 | + try { |
|
| 121 | + $cacheKey = 'health_check_' . uniqid(); |
|
| 122 | + $cacheItem = $cachePool->getItem($cacheKey); |
|
| 123 | + $cacheItem->set('ok'); |
|
| 124 | + $cachePool->save($cacheItem); |
|
| 125 | + $cachePool->deleteItem($cacheKey); |
|
| 126 | + $status['memcached'] = 'green'; |
|
| 127 | + } catch (\Throwable $e) { |
|
| 128 | + // Log error for debugging |
|
| 129 | + error_log('Memcached health check failed: ' . $e->getMessage()); |
|
| 130 | + $status['memcached'] = 'red'; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // Check RabbitMQ using php-amqp extension |
|
| 134 | + try { |
|
| 135 | + $amqp = new \AMQPConnection([ |
|
| 136 | + 'host' => $_ENV['RABBIT_MQ_HOST'] ?? 'localhost', |
|
| 137 | + 'port' => (int)($_ENV['RABBIT_MQ_PORT'] ?? 5672), |
|
| 138 | + 'login' => $_ENV['RABBIT_MQ_USER'] ?? 'guest', |
|
| 139 | + 'password' => $_ENV['RABBIT_MQ_PASSWORD'] ?? 'guest', |
|
| 140 | + 'vhost' => $_ENV['RABBIT_MQ_VHOST'] ?? '/', |
|
| 141 | + ]); |
|
| 142 | + $amqp->connect(); |
|
| 143 | + if ($amqp->isConnected()) { |
|
| 144 | + $status['rabbitmq'] = 'green'; |
|
| 145 | + } |
|
| 146 | + } catch (\Throwable $e) { |
|
| 147 | + // Log error for debugging |
|
| 148 | + error_log('RabbitMQ health check failed: ' . $e->getMessage()); |
|
| 149 | + $status['rabbitmq'] = 'red'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Check Supervisor processes |
|
| 153 | + try { |
|
| 154 | + $process = new \Symfony\Component\Process\Process(['supervisorctl', 'status', 'messenger-consume:*']); |
|
| 155 | + $process->setTimeout(10); |
|
| 156 | + $process->run(); |
|
| 157 | 157 | |
| 158 | - if ($process->isSuccessful()) { |
|
| 159 | - $output = $process->getOutput(); |
|
| 160 | - $lines = explode(PHP_EOL, trim($output)); |
|
| 161 | - $runningProcesses = 0; |
|
| 162 | - $totalProcesses = 0; |
|
| 158 | + if ($process->isSuccessful()) { |
|
| 159 | + $output = $process->getOutput(); |
|
| 160 | + $lines = explode(PHP_EOL, trim($output)); |
|
| 161 | + $runningProcesses = 0; |
|
| 162 | + $totalProcesses = 0; |
|
| 163 | 163 | |
| 164 | - foreach ($lines as $line) { |
|
| 165 | - if (trim($line) && stripos($line, 'RUNNING') !== false) { |
|
| 166 | - $runningProcesses++; |
|
| 167 | - } |
|
| 168 | - if (trim($line)) { |
|
| 169 | - $totalProcesses++; |
|
| 170 | - } |
|
| 171 | - } |
|
| 164 | + foreach ($lines as $line) { |
|
| 165 | + if (trim($line) && stripos($line, 'RUNNING') !== false) { |
|
| 166 | + $runningProcesses++; |
|
| 167 | + } |
|
| 168 | + if (trim($line)) { |
|
| 169 | + $totalProcesses++; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - if ($totalProcesses > 0 && $runningProcesses === $totalProcesses) { |
|
| 174 | - $status['supervisor'] = 'green'; |
|
| 175 | - } else { |
|
| 176 | - $status['supervisor'] = 'red'; |
|
| 177 | - } |
|
| 178 | - } else { |
|
| 179 | - $status['supervisor'] = 'red'; |
|
| 180 | - } |
|
| 181 | - } catch (\Throwable $e) { |
|
| 182 | - // Log error for debugging |
|
| 183 | - error_log('Supervisor health check failed: ' . $e->getMessage()); |
|
| 184 | - $status['supervisor'] = 'red'; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // Determine overall status |
|
| 188 | - $redServices = 0; |
|
| 189 | - $totalServices = count($status) - 1; // Exclude application_name from count |
|
| 173 | + if ($totalProcesses > 0 && $runningProcesses === $totalProcesses) { |
|
| 174 | + $status['supervisor'] = 'green'; |
|
| 175 | + } else { |
|
| 176 | + $status['supervisor'] = 'red'; |
|
| 177 | + } |
|
| 178 | + } else { |
|
| 179 | + $status['supervisor'] = 'red'; |
|
| 180 | + } |
|
| 181 | + } catch (\Throwable $e) { |
|
| 182 | + // Log error for debugging |
|
| 183 | + error_log('Supervisor health check failed: ' . $e->getMessage()); |
|
| 184 | + $status['supervisor'] = 'red'; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // Determine overall status |
|
| 188 | + $redServices = 0; |
|
| 189 | + $totalServices = count($status) - 1; // Exclude application_name from count |
|
| 190 | 190 | |
| 191 | - foreach ($status as $service => $serviceStatus) { |
|
| 192 | - if ($service !== 'application_name' && $serviceStatus === 'red') { |
|
| 193 | - $redServices++; |
|
| 194 | - } |
|
| 195 | - } |
|
| 191 | + foreach ($status as $service => $serviceStatus) { |
|
| 192 | + if ($service !== 'application_name' && $serviceStatus === 'red') { |
|
| 193 | + $redServices++; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - if ($redServices === 0) { |
|
| 198 | - $status['status'] = 'green'; |
|
| 199 | - } elseif ($redServices === $totalServices) { |
|
| 200 | - $status['status'] = 'red'; |
|
| 201 | - } else { |
|
| 202 | - $status['status'] = 'orange'; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return new JsonResponse($status); |
|
| 206 | - } |
|
| 197 | + if ($redServices === 0) { |
|
| 198 | + $status['status'] = 'green'; |
|
| 199 | + } elseif ($redServices === $totalServices) { |
|
| 200 | + $status['status'] = 'red'; |
|
| 201 | + } else { |
|
| 202 | + $status['status'] = 'orange'; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return new JsonResponse($status); |
|
| 206 | + } |
|
| 207 | 207 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | } catch (\Throwable $e) { |
| 104 | 104 | // Log error for debugging |
| 105 | - error_log('PostgreSQL health check failed: ' . $e->getMessage()); |
|
| 105 | + error_log('PostgreSQL health check failed: '.$e->getMessage()); |
|
| 106 | 106 | $status['postgres'] = 'red'; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | $status['elasticsearch'] = 'green'; |
| 113 | 113 | } catch (\Throwable $e) { |
| 114 | 114 | // Log error for debugging |
| 115 | - error_log('Elasticsearch health check failed: ' . $e->getMessage()); |
|
| 115 | + error_log('Elasticsearch health check failed: '.$e->getMessage()); |
|
| 116 | 116 | $status['elasticsearch'] = 'red'; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // Check Memcached (Symfony Cache) |
| 120 | 120 | try { |
| 121 | - $cacheKey = 'health_check_' . uniqid(); |
|
| 121 | + $cacheKey = 'health_check_'.uniqid(); |
|
| 122 | 122 | $cacheItem = $cachePool->getItem($cacheKey); |
| 123 | 123 | $cacheItem->set('ok'); |
| 124 | 124 | $cachePool->save($cacheItem); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $status['memcached'] = 'green'; |
| 127 | 127 | } catch (\Throwable $e) { |
| 128 | 128 | // Log error for debugging |
| 129 | - error_log('Memcached health check failed: ' . $e->getMessage()); |
|
| 129 | + error_log('Memcached health check failed: '.$e->getMessage()); |
|
| 130 | 130 | $status['memcached'] = 'red'; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | try { |
| 135 | 135 | $amqp = new \AMQPConnection([ |
| 136 | 136 | 'host' => $_ENV['RABBIT_MQ_HOST'] ?? 'localhost', |
| 137 | - 'port' => (int)($_ENV['RABBIT_MQ_PORT'] ?? 5672), |
|
| 137 | + 'port' => (int) ($_ENV['RABBIT_MQ_PORT'] ?? 5672), |
|
| 138 | 138 | 'login' => $_ENV['RABBIT_MQ_USER'] ?? 'guest', |
| 139 | 139 | 'password' => $_ENV['RABBIT_MQ_PASSWORD'] ?? 'guest', |
| 140 | 140 | 'vhost' => $_ENV['RABBIT_MQ_VHOST'] ?? '/', |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | } |
| 146 | 146 | } catch (\Throwable $e) { |
| 147 | 147 | // Log error for debugging |
| 148 | - error_log('RabbitMQ health check failed: ' . $e->getMessage()); |
|
| 148 | + error_log('RabbitMQ health check failed: '.$e->getMessage()); |
|
| 149 | 149 | $status['rabbitmq'] = 'red'; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | } catch (\Throwable $e) { |
| 182 | 182 | // Log error for debugging |
| 183 | - error_log('Supervisor health check failed: ' . $e->getMessage()); |
|
| 183 | + error_log('Supervisor health check failed: '.$e->getMessage()); |
|
| 184 | 184 | $status['supervisor'] = 'red'; |
| 185 | 185 | } |
| 186 | 186 | |