How to check if celery result backend is working

Question:

I am using celery with Redis.

Current Redis is used as a broker and as a result backend.

BROKER_TRANSPORT = 'redis'
BROKER_URL = 'redis://domain:8888/0'
CELERY_RESULT_BACKEND = 'redis://domain:8888/0'

I want to clear few things:

  1. What is the benefit of using the result backend? I mean what I will get by using it
  2. How can I see that it is working? I mean will something be stored in Redis? Will that storage is permanent? How can I query that? Will that storage grow with time etc
  3. Can I monitor that result backend stuff with the celery flower?
Asked By: Karl

||

Answers:

A result backend is exactly what it sounds like, all it does is store results from tasks.

Let’s say that you have the following task that actually returns a value.

@task
def sum(x, y):
    return x + y

At some point, you call this task. If you do not have a result backend, get() will throw an error (or a warning, I forget which). If you do have a result backend (and assuming it’s properly configured), task.get() will poll your redis-backend for a result from the task_id associated with task and then return it to you via whatever serializer you specified.

from tasks import sum

task = sum.delay(3, 4)
task.get()

You can see that it works by just calling get() (and waiting to completion) on a task that you’ve sent off to the broker. You can read more about working with celery results from the official documentation.

You can in principle poll your redis database from the redis-cli, but I see no reason to. You can view results in flower by going to one of the actual task detail views and checking the “result” field under the “Basic Task Options” table. e.g. http://flower.myserver.com/task/

Answered By: Thtu

The question is already answered. So, I would like to show the snapshots of what celery stores in DB just to give an idea.

Here, I have used the default settings of celery with MySQL database as result_backend.

It has created two tables:

1. celery_taskmeta

celery_taskmeta

and

2. celery_tasksetmeta

celery_taskset_meta

Answered By: Deepam Gupta
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.