Prisacari Dmitrii
Prisacari Dmitrii

Reputation: 2106

Celery: How to store results only for the last chain link?

I have a task chain:

result = celery.chain(task_a.s(), task_b.s())()

I am interested only in result of task_b(), however celery saves results of both task_a() and task_b() to backend.

Is there any way to store the results only for task_b()?

Upvotes: 2

Views: 1113

Answers (2)

MartinP
MartinP

Reputation: 535

Try mix link with ignore results for first task.

add.apply_async((2, 2),ignore_result=True, link=add.s(16))

Upvotes: -1

Tomasz Zieliński
Tomasz Zieliński

Reputation: 16367

I haven't tested this, but based on the docs (1, 2) it should be possible to add ignore_result=True parameter to .s() calls.

If the above doesn't work then you can always configure the whole task to not store results (by adding ignore_result=True to task class or decorator)

Important: as per Celery docs, tasks used within chords cannot ignore their results. So while it shouldn't concern chains, it's something to be aware of if you plan to use chords.

Upvotes: 0

Related Questions