Skip to content

Commit d2b1bf3

Browse files
committed
fix: clean up stale db connection in enrollment update thread
1 parent f260bb3 commit d2b1bf3

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tcf_website/api/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""DRF Viewsets"""
33
import asyncio
44
from threading import Thread
5+
from django.db import connection
56
from django.db.models import Avg, Sum
67
from django.http import JsonResponse
78
from rest_framework import viewsets
@@ -195,6 +196,8 @@ def _run_update():
195196
asyncio.run(update_enrollment_data(pk))
196197
except (asyncio.TimeoutError, requests.RequestException, ValueError) as exc:
197198
print(f"Enrollment update failed for course {pk}: {exc}")
199+
finally:
200+
connection.close()
198201

199202
thread = Thread(target=_run_update, daemon=True)
200203
thread.start()

0 commit comments

Comments
 (0)