Celery tasks without result write to result backend
Solution 1
From celery document you can set ignore result flag to True. http://docs.celeryproject.org/en/latest/reference/celery.app.task.html?highlight=default_retry_delay#celery.app.task.Task.ignore_result
For example:
@app.task(ignore_result=True)
def taskWithNoResult():
# ...code without return..
Solution 2
Global Config
app.conf.task_ignore_result = True
Locally close return task results:
@app.task(ignore_result=True)
def add(...):
If you only want to return and persist the abnormal results of the task execution failure for subsequent investigation and analysis, then you can apply the following configuration while using the database as a Result Backend:
Only store task errors in the result backend.
app.conf.task_ignore_result = True
app.conf.task_store_errors_even_if_ignored = True
![Sergey Luchko](https://i.stack.imgur.com/eAIPQ.jpg?s=256&g=1)
Sergey Luchko
Updated on June 07, 2022Comments
-
Sergey Luchko about 2 years
I have some tasks which should return result, and some tasks that don't. I want to force tasks which shouldn't return result not to write anything in result backend (for example None). How can I achieve that in Celery?
For example it's my tasks:
@app.task def taskWithResult(): # ...code... return res @app.task def taskWithNoResult(): # ...code without return...
And also I have special queue for some others task which also don't return any result, can I mark that queue as with tasks which mustn't write in result backend?
-
kkiat over 7 yearsYou can use apply_async to choose the queue for task. link
-
Thorvald about 3 yearsIt's worth nothing this can be applied on specific tasks, e.g: @task(name="test") def test(ignore_result=True, store_errors_even_if_ignored=True):