Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery: Redis as broker leaving task meta keys

I have celery app with Redis as broker.

The code consist of the following in a loop :

running = []
res = add.apply_async([1,2], queue='add')
running.append(res)

while running:
    r = running.pop()
    if r.ready():
        print r.get()
    else:
        running.insert(0,r)

everything works fine but when i redis-cli into redis and execute keys * I see bunch of celery-task-meta keys.

Why arent they cleaned up?
What are those for?

--

[EDIT]

I've read about CELERY_TASK_RESULT_EXPIRES setting.
Is it possible for the task keys in Redis to be cleaned up right after the result is read rather than wait until the expiration time?

like image 659
ealeon Avatar asked Oct 18 '22 20:10

ealeon


1 Answers

From the Celery Doc:

AsyncResult.forget()
   Forget about (and possibly remove the result of) this task.

You have to first r.get() then r.forget()

But, You needn't cleaned up the keys. For,doc say that:

CELERY_TASK_RESULT_EXPIRES

Default is to expire after 1 day.

like image 70
bin381 Avatar answered Oct 23 '22 09:10

bin381