mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-07 13:58:11 +08:00
Fix max attempts for value 1 (#185)
This commit is contained in:
+15
-14
@@ -117,25 +117,19 @@ def save_task(task, broker: Broker):
|
|||||||
|
|
||||||
# check if this task has previous results
|
# check if this task has previous results
|
||||||
try:
|
try:
|
||||||
existing_task = Task.objects.get(id=task["id"], name=task["name"])
|
task_obj = Task.objects.get(id=task["id"], name=task["name"])
|
||||||
# only update the result if it hasn't succeeded yet
|
# only update the result if it hasn't succeeded yet
|
||||||
if not existing_task.success:
|
if not task_obj.success:
|
||||||
existing_task.stopped = task["stopped"]
|
task_obj.stopped = task["stopped"]
|
||||||
existing_task.result = task["result"]
|
task_obj.result = task["result"]
|
||||||
existing_task.success = task["success"]
|
task_obj.success = task["success"]
|
||||||
existing_task.attempt_count = existing_task.attempt_count + 1
|
task_obj.attempt_count = task_obj.attempt_count + 1
|
||||||
existing_task.save()
|
task_obj.save()
|
||||||
|
|
||||||
if (
|
|
||||||
Conf.MAX_ATTEMPTS > 0
|
|
||||||
and existing_task.attempt_count >= Conf.MAX_ATTEMPTS
|
|
||||||
):
|
|
||||||
broker.acknowledge(task["ack_id"])
|
|
||||||
|
|
||||||
except Task.DoesNotExist:
|
except Task.DoesNotExist:
|
||||||
# convert func to string
|
# convert func to string
|
||||||
func = get_func_repr(task["func"])
|
func = get_func_repr(task["func"])
|
||||||
Task.objects.create(
|
task_obj = Task.objects.create(
|
||||||
id=task["id"],
|
id=task["id"],
|
||||||
name=task["name"],
|
name=task["name"],
|
||||||
func=func,
|
func=func,
|
||||||
@@ -150,6 +144,13 @@ def save_task(task, broker: Broker):
|
|||||||
success=task["success"],
|
success=task["success"],
|
||||||
attempt_count=1,
|
attempt_count=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
Conf.MAX_ATTEMPTS > 0
|
||||||
|
and task_obj.attempt_count >= Conf.MAX_ATTEMPTS
|
||||||
|
):
|
||||||
|
broker.acknowledge(task["ack_id"])
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Could not save task result")
|
logger.exception("Could not save task result")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user