Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if celery result backend is working

I am using celery with redis.

Current redis is used as broker and as 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 result backend. I mean what i will get by using it
  2. How can i see that its working . I mean will something be stored in redis. Wll 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 celery flower
like image 733
Karl Avatar asked May 03 '16 23:05

Karl


2 Answers

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

like image 102
Deepam Gupta Avatar answered Nov 01 '22 01:11

Deepam Gupta


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/

like image 44
Thtu Avatar answered Nov 01 '22 03:11

Thtu