Skip to content

Commit

Permalink
Fixes #225 (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyhei committed May 7, 2021
1 parent 57ae1dc commit ad77ad7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions django_q/cluster.py
Expand Up @@ -476,8 +476,10 @@ def save_task(task, broker: Broker):
# SAVE LIMIT > 0: Prune database, SAVE_LIMIT 0: No pruning
close_old_django_connections()
try:
if task["success"] and 0 < Conf.SAVE_LIMIT <= Success.objects.count():
Success.objects.last().delete()
with db.transaction.atomic():
last = Success.objects.select_for_update().last()
if task["success"] and 0 < Conf.SAVE_LIMIT <= Success.objects.count():
last.delete()
# check if this task has previous results
if Task.objects.filter(id=task["id"], name=task["name"]).exists():
existing_task = Task.objects.get(id=task["id"], name=task["name"])
Expand Down

0 comments on commit ad77ad7

Please sign in to comment.