Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:(schedule DB conn error) close stale broker connections only #2

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions django_q/brokers/orm.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from datetime import timedelta
from time import sleep

from django import db
from django.db import transaction
from django.db import transaction, connections
from django.utils import timezone

from django_q.brokers import Broker
from django_q.conf import Conf, logger
from django_q.models import OrmQ
from django_q.models import OrmQ, Schedule


def _timeout():
Expand All @@ -23,7 +22,8 @@ def get_connection(list_key: str = None):
# Make sure stale connections in the broker thread are explicitly
# closed before attempting DB access.
# logger.debug("Broker thread calling close_old_connections")
db.close_old_connections()
connection = connections[Conf.ORM]
connection.close_if_unusable_or_obsolete()
else:
logger.debug("Broker in an atomic transaction")
return OrmQ.objects.using(Conf.ORM)
Expand Down