mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-28 14:48:13 +08:00
allow atomic on external db (#14)
Co-authored-by: Rajeev KL <rajeev@labmoneta.io>
This commit is contained in:
co-authored by
Rajeev KL
parent
00fe611b86
commit
ce98aaa15c
+4
-2
@@ -496,7 +496,9 @@ def save_task(task, broker: Broker):
|
|||||||
if Conf.SAVE_LIMIT_PER == "func":
|
if Conf.SAVE_LIMIT_PER == "func":
|
||||||
value = get_func_repr(value)
|
value = get_func_repr(value)
|
||||||
filters[Conf.SAVE_LIMIT_PER] = value
|
filters[Conf.SAVE_LIMIT_PER] = value
|
||||||
with db.transaction.atomic():
|
|
||||||
|
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):
|
||||||
last = Success.objects.filter(**filters).select_for_update().last()
|
last = Success.objects.filter(**filters).select_for_update().last()
|
||||||
if task["success"] and 0 < Conf.SAVE_LIMIT <= Success.objects.filter(**filters).count():
|
if task["success"] and 0 < Conf.SAVE_LIMIT <= Success.objects.filter(**filters).count():
|
||||||
last.delete()
|
last.delete()
|
||||||
@@ -599,7 +601,7 @@ def scheduler(broker: Broker = None):
|
|||||||
broker = get_broker()
|
broker = get_broker()
|
||||||
close_old_django_connections()
|
close_old_django_connections()
|
||||||
try:
|
try:
|
||||||
database_to_use = {"using": Conf.ORM} if not Conf.HAS_REPLICA else {}
|
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(**database_to_use):
|
||||||
for s in (
|
for s in (
|
||||||
Schedule.objects.select_for_update()
|
Schedule.objects.select_for_update()
|
||||||
|
|||||||
Reference in New Issue
Block a user