'how to get the status of running tasks with TaskResult

I have a running celery task. I want to get the status of the task with django_celery_results. But I noticed that the model only gets updated once the task completes running. How do I get the status of a running task with TaskResult?

Example views

def test(request):
    task_id = test_task.delay()
    status = TaskResult.objects.filter(task_id=task_id)
    print(status)

When I run the above view this is the result I get

<QuerySet []>


Solution 1:[1]

Try adding track_started parameter in @task decorator.

For instance:


    from myproject.celery import celery_app

    @celery_app.task(
        bind=True,
        track_started=True
    )
    def my_task(self, parameter_a):
       pass

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2283748