Fix use of database router for write queries and remove Conf.HAS_REPLICA (#61)

Co-authored-by: Marc Sabatier
This commit is contained in:
msabatier
2023-01-18 02:12:13 +01:00
committed by GitHub
co-authored by Marc Sabatier
parent a013591de5
commit 650c3b1524
5 changed files with 17 additions and 79 deletions
+2 -13
View File
@@ -20,7 +20,6 @@ except core.exceptions.AppRegistryNotReady:
django.setup()
from django.conf import settings
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
@@ -541,12 +540,7 @@ def save_task(task, broker: Broker):
value = get_func_repr(value)
filters[Conf.SAVE_LIMIT_PER] = value
database_to_use = (
{"using": Conf.ORM if Conf.ORM else Schedule.objects.db}
if not Conf.HAS_REPLICA
else {}
)
with db.transaction.atomic(**database_to_use):
with db.transaction.atomic(using=db.router.db_for_write(Success)):
last = Success.objects.filter(**filters).select_for_update().last()
if (
task["success"]
@@ -652,12 +646,7 @@ def scheduler(broker: Broker = None):
broker = get_broker()
close_old_django_connections()
try:
database_to_use = (
{"using": Conf.ORM if Conf.ORM else Schedule.objects.db}
if not Conf.HAS_REPLICA
else {}
)
with db.transaction.atomic(**database_to_use):
with db.transaction.atomic(using=db.router.db_for_write(Schedule)):
for s in (
Schedule.objects.select_for_update()
.exclude(repeats=0)