PostgresSQL DB v15 and health check endpoint (#5312)
parent
6cf67dba9e
commit
980c019427
@ -0,0 +1,3 @@
|
|||||||
|
# Copyright (C) 2022 CVAT.ai Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
# Copyright (C) 2022 CVAT.ai Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
from health_check.plugins import plugin_dir
|
||||||
|
|
||||||
|
class HealthConfig(AppConfig):
|
||||||
|
name = 'cvat.apps.health'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
from .backends import OPAHealthCheck
|
||||||
|
plugin_dir.register(OPAHealthCheck)
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
# Copyright (C) 2022 CVAT.ai Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from health_check.backends import BaseHealthCheckBackend
|
||||||
|
from health_check.exceptions import HealthCheckException
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
class OPAHealthCheck(BaseHealthCheckBackend):
|
||||||
|
critical_service = True
|
||||||
|
|
||||||
|
def check_status(self):
|
||||||
|
opa_health_url = f'{settings.IAM_OPA_HOST}/health?bundles'
|
||||||
|
try:
|
||||||
|
response = requests.get(opa_health_url)
|
||||||
|
response.raise_for_status()
|
||||||
|
except requests.RequestException as e:
|
||||||
|
raise HealthCheckException(str(e))
|
||||||
|
|
||||||
|
def identifier(self):
|
||||||
|
return self.__class__.__name__
|
||||||
@ -1,8 +1,11 @@
|
|||||||
SELECT pg_terminate_backend(pg_stat_activity.pid)
|
SELECT :'from' = 'cvat' AS fromcvat \gset
|
||||||
FROM pg_stat_activity
|
|
||||||
WHERE pg_stat_activity.datname = 'cvat' AND pid <> pg_backend_pid();
|
|
||||||
|
|
||||||
DROP DATABASE IF EXISTS :to;
|
\if :fromcvat
|
||||||
|
SELECT pg_terminate_backend(pg_stat_activity.pid)
|
||||||
|
FROM pg_stat_activity
|
||||||
|
WHERE pg_stat_activity.datname = 'cvat' AND pid <> pg_backend_pid();
|
||||||
|
\endif
|
||||||
|
|
||||||
CREATE DATABASE :to WITH TEMPLATE :from;
|
DROP DATABASE IF EXISTS :to WITH (FORCE);
|
||||||
|
|
||||||
|
CREATE DATABASE :to WITH TEMPLATE :from;
|
||||||
|
|||||||
Loading…
Reference in New Issue