From 66771f274a8ffbf0fefa2fd1508dbc9258a8402b Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Tue, 19 Jan 2016 22:49:28 +0100 Subject: [PATCH] Save task now creates or updates This way failed tasks that get requeued can have a changed status and result --- django_q/cluster.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index 002efef..68d226b 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -408,17 +408,19 @@ def save_task(task, broker): try: if task['success'] and 0 < Conf.SAVE_LIMIT <= Success.objects.count(): Success.objects.last().delete() - Task.objects.create(id=task['id'], - name=task['name'], - func=task['func'], - hook=task.get('hook'), - args=task['args'], - kwargs=task['kwargs'], - started=task['started'], - stopped=task['stopped'], - result=task['result'], - group=task.get('group'), - success=task['success']) + Task.objects.update_or_create(id=task['id'], + name=task['name'], + defaults={ + 'func': task['func'], + 'hook': task.get('hook'), + 'args': task['args'], + 'kwargs': task['kwargs'], + 'started': task['started'], + 'stopped': task['stopped'], + 'result': task['result'], + 'group': task.get('group'), + 'success': task['success']} + ) except Exception as e: logger.error(e)