소스 검색

Task: Add attribute "ignore_result": Don't store the status and return value.
This means you can't use the :class:`celery.result.AsyncResult` to check if the task is
done, or get its return value. Only use if you need the performance
and is able live without these features. Any exceptions raised will
store the return value/status as usual.
ignore the return value and not save it and the tasks status.

Ask Solem 16 년 전
부모
커밋
55b9910a20
2개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 9 0
      celery/task.py
  2. 3 1
      celery/worker.py

+ 9 - 0
celery/task.py

@@ -182,6 +182,14 @@ class Task(object):
     
         The message priority. A number from ``0`` to ``9``.
 
+    .. attribute:: ignore_result
+
+        Don't store the status and return value. This means you can't
+        use the :class:`celery.result.AsyncResult` to check if the task is
+        done, or get its return value. Only use if you need the performance
+        and is able live without these features. Any exceptions raised will
+        store the return value/status as usual.
+
     .. attribute:: disable_error_emails
 
         Disable all error e-mails for this task (only applicable if
@@ -229,6 +237,7 @@ class Task(object):
     immediate = False
     mandatory = False
     priority = None
+    ignore_result = False
     disable_error_emails = False
 
     def __init__(self):

+ 3 - 1
celery/worker.py

@@ -63,6 +63,7 @@ def jail(task_id, task_name, func, args, kwargs):
         the exception instance on failure.
 
     """
+    ignore_result = getattr(func, "ignore_result", False)
     timer_stat = TaskTimerStats.start(task_id, task_name, args, kwargs)
 
     # See: http://groups.google.com/group/django-users/browse_thread/
@@ -97,7 +98,8 @@ def jail(task_id, task_name, func, args, kwargs):
         default_backend.mark_as_failure(task_id, exc)
         retval = ExceptionInfo(sys.exc_info())
     else:
-        default_backend.mark_as_done(task_id, result)
+        if not ignore_result:
+            default_backend.mark_as_done(task_id, result)
         retval = result
     finally:
         timer_stat.stop()