Skip to content

Commit

Permalink
Fix database connection closed (#4111)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Jul 25, 2024
1 parent f77cf86 commit 30f6eba
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bims/tasks/email_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import zipfile

from celery import shared_task
from django.db import DatabaseError, connection, InterfaceError
from openpyxl import load_workbook

from bims.utils.domain import get_current_domain
Expand Down Expand Up @@ -49,7 +50,12 @@ def send_csv_via_email(
if download_request and not download_request.request_file:
download_request.request_category = file_name
download_request.request_file = csv_file
download_request.save()
try:
download_request.save()
except (DatabaseError, InterfaceError):
# Attempt to reconnect and save again
connection.connect()
download_request.save()

email_template = 'csv_download/csv_created'
if download_request and download_request.resource_type == DownloadRequest.PDF:
Expand Down
1 change: 1 addition & 0 deletions core/settings/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'grappelli',
'django_tenants',
'tenants',
'django_dbconn_retry',

'colorfield',
'polymorphic',
Expand Down
1 change: 1 addition & 0 deletions deployment/docker/REQUIREMENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ celery==5.3.6
django-celery-results==2.5.1
django-tenants==3.6.1
tenant-schemas-celery==2.2.0
django-dbconn-retry==0.1.7
1 change: 1 addition & 0 deletions deployment/production/REQUIREMENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ celery==5.3.6
django-celery-results==2.5.1
django-tenants==3.6.1
tenant-schemas-celery==2.2.0
django-dbconn-retry==0.1.7

0 comments on commit 30f6eba

Please sign in to comment.