Oskar Persson
Oskar Persson

Reputation: 6753

How do I retry a revoked Celery task using AsyncResult

I want to retry a previously revoked task using a AsyncResult object but I get an error saying that the task will be discarded as soon as I run the task

worker_1 | [2019-06-27 16:04:23,094: INFO/MainProcess] Discarding revoked task: ...

According to the docs a list of revoked tasks is stored in memory by the worker and isn't cleared until the worker is restarted.

Is there another way I can cancel a running task instead of revoking it or can I somehow remove the task from the list of revoked task?

Upvotes: 2

Views: 986

Answers (1)

DejanLekic
DejanLekic

Reputation: 19787

It does not make sense to bring back the revoked task from "the dead".

What I recommend you do is:

  1. Create a new task with the same args as the revoked one.

  2. Use the update_state() on the task, and specify the metadata that you can use to relate two different tasks (the revoked one, and the new one). Something like tsk.update_state(meta={"job-id": "babadeda123", "client-id": "skynet", "previous-task-id": "64fb925e-86cb-4d29-b4e5-33f41f8416cc"}) where the 64fb925e-86cb-4d29-b4e5-33f41f8416cc is the ID of the revoked task.

Upvotes: 1

Related Questions