I try to implement a working example with abortable tasks in celery (5.1.2) (code snippet bellow). When I call "abort" method on AbortableAsyncResult instance exception "RuntimeError: RPC backend missing task request for {task_id}" is raised.
What do I do wrong? Why the code snippet does not work?
I was trying to google the answer but got only links to old celery issues that mention that AbortableTask will be removed in celery 4.0.0 (I'm using celery 5.1.2, and AbortableTask is present there).
from time import sleep
from celery import Celery
from celery.contrib.abortable import AbortableTask
celery_app = Celery(
broker = "amqp://login:pass@rabbitmq:5672"
backend = "rpc://"
include = ["root.subpath.my_tasks_module"]
@celery_app.task(acks_late=True, bind=True, base=AbortableTask)
def my_task(self, a, b):
sleep(100)
if self.is_aborted():
return None
return a * b
def foo():
abortable_async_result = my_task.delay(4, 4)
sleep(10)
abortable_async_result.abort() # This call raises exception
Thanks for your attention and answers.