Search code examples
celery

How do I map tasks against a user id in celery?


I have a requirement, that I want to give user control over their pending tasks, and the tasks which failed on my app. So for that I want to create something like tasks should be mapped against the user id.

Suppose I have an API /get_tasks/user_id I should be getting all the tasks, against that user, How do I do it in celery that it adds tasks in the particular user_id group?

I see the documentation did not find anything related? I want to know how can I do it in celery if it supports but if it does not support it how can I accomplish the same?


Solution

  • Your service should manage such information. It is not job for Celery.

    As you probably know when you produce a task via apply_async(), delay(), or send_task(), you get an AsyncResult object. Among other things it contains the task ID. Your service should grab this task ID, and write a record somewhere along the user ID, and whatever details you need for your service to successfully do what it is supposed to do.