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 (http://iambusychangingtheworld.blogspot.com/2013/07/django-celery-display-progress-bar-of.html). 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:
Try to call the task which will return a fail result:
>> from tasks import add
>> job = add.delay(5,4)
>> job.state
SUCCESS
>> job.result
FAIL
With this you can figure exactly what the result of the task is.
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:
Try to call the task which will return a fail result:
>> from tasks import add
>> job = add.delay(5,4)
>> job.state
SUCCESS
>> job.result
FAIL
With this you can figure exactly what the result of the task is.
Comments
Post a Comment