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?
Celery uses a result backend to keep track of the tasks' states. In the previous tutorial, we saw how Celery works and how to integrate it into a Django application. In this tutorial, we are going to use the RPC (RabbitMQ/AMQP) result backend to store and retrieve the states of tasks.
Celery will stop retrying after 7 failed attempts and raise an exception.
Process of Task Execution by Celery can be broken down into:Your application sends the tasks to the task broker, it is then reserved by a worker for execution & finally the result of task execution is stored in the result backend.
app.conf.task_ignore_result = True
@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:
app.conf.task_ignore_result = True
app.conf.task_store_errors_even_if_ignored = True
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..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With