Search code examples
djangocelerydjango-celery

How to find which database entry has been created using celery task id


In one of my celery tasks, I'm creating database entries. I know how to read the status of my celery tasks :

from celery.result import AsyncResult
res = AsyncResult("my-task-id")
res.ready()

But I want to know that exactly which database entry was created on a specific task by using a celery task ID. How can I do this?

Thanks in advance.


Solution

  • When you insert new database entries, you will get the IDs of those newly inserted rows from your query.

    Celery tasks can return "results". After inserting the database entries, just return those id / ids.

    You can now retrieve the result of a task by task id to get the database ids.