Skip to content
14 changes: 13 additions & 1 deletion dojo/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from logging.config import dictConfig

from celery import Celery, Task
from celery.signals import setup_logging
from celery.signals import setup_logging, task_postrun, task_prerun
from django.conf import settings

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -119,6 +119,18 @@ def config_loggers(*args, **kwags):
dictConfig(settings.LOGGING)


@task_prerun.connect
def close_old_db_connections_before_task(**kwargs):
from django.db import close_old_connections # noqa: PLC0415
Comment thread
rossops marked this conversation as resolved.
Outdated
close_old_connections()


@task_postrun.connect
def close_old_db_connections_after_task(**kwargs):
from django.db import close_old_connections # noqa: PLC0415
close_old_connections()


# from celery import current_app

# _ = current_app.loader.import_default_modules()
Expand Down
2 changes: 2 additions & 0 deletions dojo/settings/settings.dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
},
}

DATABASES["default"]["CONN_MAX_AGE"] = 3600

# Track migrations through source control rather than making migrations locally
if env("DD_TRACK_MIGRATIONS"):
MIGRATION_MODULES = {"dojo": "dojo.db_migrations"}
Expand Down
Loading