diff options
author | 2024-06-07 13:23:59 +0200 | |
---|---|---|
committer | 2024-06-07 13:23:59 +0200 | |
commit | a89fe54923d2ff39400f6bd1bdaa68959cc43327 (patch) | |
tree | 4c4cc7bc45c407b6b12362b63c1fcb4da33b539e | |
parent | Merge pull request #1336 from python-discord/dependabot/pip/sentry-sdk-2.5.0 (diff) |
add a management command to close all connectionsmgmt-cmd-kill-db-cnx
-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) |