Using the return value of a celery task as the result indicator

Sometimes we cannot measure the progress or percentage completed of a job when using celery task ( You can only say if it done or not by checking the status of the task.

Here is a case, where the business code returns a failed result, but the task is still executed successfully. How can you tell? Luckily, you can use the result attribute of the task to get the return value of the business code. For example:

Run the celery worker:

celery -A tasks worker --loglevel=info

Try to call the task which will return a fail result:

>> from tasks import add
>> job = add.delay(5,4)
>> job.state
>> job.result

With this you can figure exactly what the result of the task is.