Skip to content

Commit c252f5b

Browse files
committed
test: add health checks
1 parent 1b7425e commit c252f5b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace App\Controller;
4+
5+
use Exception;
6+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7+
use Symfony\Component\Routing\Annotation\Route;
8+
use Doctrine\ORM\EntityManager;
9+
use Symfony\Component\HttpFoundation\JsonResponse;
10+
use Symfony\Component\HttpFoundation\Response;
11+
use League\Flysystem\FilesystemOperator;
12+
13+
14+
/**
15+
* @Route("/health")
16+
*/
17+
class HealthController extends AbstractController
18+
{
19+
/**
20+
* Checks for Database connection
21+
*
22+
* @Route("/db", name="heatlh_db")
23+
*/
24+
public function headthDB(EntityManager $entityManager)
25+
{
26+
try{
27+
$entityManager->getConnection()->connect();
28+
$check = $entityManager->getConnection()->isConnected();
29+
$httpCode = $check ? Response::HTTP_OK : Response::HTTP_SERVICE_UNAVAILABLE;
30+
return new JsonResponse($check, $httpCode);
31+
} catch (Exception $e){
32+
return new JsonResponse(False, Response::HTTP_NOT_FOUND);
33+
}
34+
}
35+
36+
/**
37+
* Checks for Database connection
38+
*
39+
* @Route("/s3", name="heatlh_s3")
40+
*/
41+
public function headthS3(FilesystemOperator $dataStorage)
42+
{
43+
try {
44+
$dataStorage->listContents('/', False);
45+
return new JsonResponse(True, Response::HTTP_OK);
46+
} catch (Exception $e) {
47+
return new JsonResponse(False, Response::HTTP_NOT_FOUND);
48+
}
49+
}
50+
51+
}

0 commit comments

Comments
 (0)