-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthController.php
More file actions
66 lines (59 loc) · 1.95 KB
/
Copy pathHealthController.php
File metadata and controls
66 lines (59 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace App\Controller\Api;
use App\Storage\ValidationsStorage;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use League\Flysystem\FilesystemOperator;
use Psr\Log\LoggerInterface;
/**
* @Route("/health")
*/
class HealthController extends AbstractController
{
public function __construct(
private LoggerInterface $logger,
private ValidationsStorage $storage){
}
/**
* Checks for Database connection
*
* @Route("/db", name="health_db")
*/
public function healthDB(EntityManagerInterface $entityManager)
{
$sql = "SELECT postgis_version() as postgis_version";
$this->logger->info('get postgis version',[
'sql' => $sql
]);
try{
$stmt = $entityManager->getConnection()->prepare($sql);
$result = $stmt->executeQuery();
return new JsonResponse($result->fetchOne(), Response::HTTP_OK);
} catch (Exception $e){
$this->logger->error((string) $e);
return new JsonResponse($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* Checks for S3 connection
*
* @Route("/s3", name="health_s3")
*/
public function healthS3()
{
$this->logger->info('list files from S3 bucket...');
try {
$files = $this->storage->getStorage()->listContents('.', false);
$numFiles = count($files->toArray());
return new JsonResponse('found '.$numFiles.' files', Response::HTTP_OK);
} catch (Exception $e) {
$this->logger->error((string) $e);
return new JsonResponse("fail to list files from S3 bucket", Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
}