diff options
-rw-r--r-- | pydis_site/apps/api/management/__init__.py | 0 | ||||
-rw-r--r-- | pydis_site/apps/api/management/commands/__init__.py | 0 | ||||
-rw-r--r-- | pydis_site/apps/api/management/commands/close_db_connections.py | 19 |
3 files changed, 19 insertions, 0 deletions
diff --git a/pydis_site/apps/api/management/__init__.py b/pydis_site/apps/api/management/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/pydis_site/apps/api/management/__init__.py diff --git a/pydis_site/apps/api/management/commands/__init__.py b/pydis_site/apps/api/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/pydis_site/apps/api/management/commands/__init__.py diff --git a/pydis_site/apps/api/management/commands/close_db_connections.py b/pydis_site/apps/api/management/commands/close_db_connections.py new file mode 100644 index 00000000..4de74a92 --- /dev/null +++ b/pydis_site/apps/api/management/commands/close_db_connections.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand +from django.db import connections +import logging + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + """A command to to close all the open connections to the database.""" + + help = "Closes all the open connections to the database" + + def handle(self, *args, **options) -> None: + """Handle the connection closing command invocation.""" + logger.info("Closing all database connections") + try: + connections.close_all() + except Exception as e: + logger.exception(e) |