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