mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-03 09:28:12 +08:00
Fix connection issues with CONN_MAX_AGE > 0 (#9)
Co-authored-by: Marc Sabatier <marc@sabatier.online>
This commit is contained in:
co-authored by
Marc Sabatier
parent
1edb426541
commit
803618da03
+5
-3
@@ -213,8 +213,9 @@ class Sentinel:
|
|||||||
:param process: the process to reincarnate
|
:param process: the process to reincarnate
|
||||||
:type process: Process or None
|
:type process: Process or None
|
||||||
"""
|
"""
|
||||||
|
# close connections before spawning new process
|
||||||
if not Conf.SYNC:
|
if not Conf.SYNC:
|
||||||
db.connections.close_all() # Close any old connections
|
db.connections.close_all()
|
||||||
if process == self.monitor:
|
if process == self.monitor:
|
||||||
self.monitor = self.spawn_monitor()
|
self.monitor = self.spawn_monitor()
|
||||||
logger.error(_(f"reincarnated monitor {process.name} after sudden death"))
|
logger.error(_(f"reincarnated monitor {process.name} after sudden death"))
|
||||||
@@ -238,8 +239,9 @@ class Sentinel:
|
|||||||
def spawn_cluster(self):
|
def spawn_cluster(self):
|
||||||
self.pool = []
|
self.pool = []
|
||||||
Stat(self).save()
|
Stat(self).save()
|
||||||
|
# close connections before spawning new process
|
||||||
if not Conf.SYNC:
|
if not Conf.SYNC:
|
||||||
db.connection.close()
|
db.connections.close_all()
|
||||||
# spawn worker pool
|
# spawn worker pool
|
||||||
for __ in range(self.pool_size):
|
for __ in range(self.pool_size):
|
||||||
self.spawn_worker()
|
self.spawn_worker()
|
||||||
@@ -695,7 +697,7 @@ def close_old_django_connections():
|
|||||||
logger.warning(
|
logger.warning(
|
||||||
"Preserving django database connections because sync=True. Beware "
|
"Preserving django database connections because sync=True. Beware "
|
||||||
"that tasks are now injected in the calling context/transactions "
|
"that tasks are now injected in the calling context/transactions "
|
||||||
"which may result in unexpected bahaviour."
|
"which may result in unexpected behaviour."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
db.close_old_connections()
|
db.close_old_connections()
|
||||||
|
|||||||
Reference in New Issue
Block a user