mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-08 06:38:11 +08:00
add attempt_count to task
This commit is contained in:
@@ -478,7 +478,12 @@ def save_task(task, broker: Broker):
|
|||||||
existing_task.stopped = task["stopped"]
|
existing_task.stopped = task["stopped"]
|
||||||
existing_task.result = task["result"]
|
existing_task.result = task["result"]
|
||||||
existing_task.success = task["success"]
|
existing_task.success = task["success"]
|
||||||
|
existing_task.attempt_count = existing_task.attempt_count + 1
|
||||||
existing_task.save()
|
existing_task.save()
|
||||||
|
|
||||||
|
if 0 < Conf.ATTEMPT_COUNT == existing_task.attempt_count:
|
||||||
|
broker.acknowledge(task['ack_id'])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
Task.objects.create(
|
Task.objects.create(
|
||||||
id=task["id"],
|
id=task["id"],
|
||||||
|
|||||||
@@ -164,6 +164,9 @@ class Conf:
|
|||||||
# Optional error reporting setup
|
# Optional error reporting setup
|
||||||
ERROR_REPORTER = conf.get("error_reporter", {})
|
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()
|
# OSX doesn't implement qsize because of missing sem_getvalue()
|
||||||
try:
|
try:
|
||||||
QSIZE = Queue().qsize() == 0
|
QSIZE = Queue().qsize() == 0
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class Task(models.Model):
|
|||||||
started = models.DateTimeField(editable=False)
|
started = models.DateTimeField(editable=False)
|
||||||
stopped = models.DateTimeField(editable=False)
|
stopped = models.DateTimeField(editable=False)
|
||||||
success = models.BooleanField(default=True, editable=False)
|
success = models.BooleanField(default=True, editable=False)
|
||||||
|
attempt_count = models.IntegerField(default=0)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_result(task_id):
|
def get_result(task_id):
|
||||||
|
|||||||
Reference in New Issue
Block a user