add attempt_count to task

This commit is contained in:
Tim O'Meara
2020-08-11 10:16:31 -05:00
parent 07d0a8c0d1
commit 3c3395f24b
3 changed files with 9 additions and 0 deletions
+5
View File
@@ -478,7 +478,12 @@ def save_task(task, broker: Broker):
existing_task.stopped = task["stopped"]
existing_task.result = task["result"]
existing_task.success = task["success"]
existing_task.attempt_count = existing_task.attempt_count + 1
existing_task.save()
if 0 < Conf.ATTEMPT_COUNT == existing_task.attempt_count:
broker.acknowledge(task['ack_id'])
else:
Task.objects.create(
id=task["id"],
+3
View File
@@ -164,6 +164,9 @@ class Conf:
# Optional error reporting setup
ERROR_REPORTER = conf.get("error_reporter", {})
# Optional attempt count. set to 0 for infinite attempts
ATTEMPT_COUNT = conf.get('attempt_count', 0)
# OSX doesn't implement qsize because of missing sem_getvalue()
try:
QSIZE = Queue().qsize() == 0
+1
View File
@@ -29,6 +29,7 @@ class Task(models.Model):
started = models.DateTimeField(editable=False)
stopped = models.DateTimeField(editable=False)
success = models.BooleanField(default=True, editable=False)
attempt_count = models.IntegerField(default=0)
@staticmethod
def get_result(task_id):