0

I have a profile page where user can see all his information.

I want to create a button so the user can pull some specific external information.

The button should start a celery task, and when the task is completed, the user should get a message with "completed"

How can I do this?

<a href="/start-task/">Pull external info</a>

My "start-task" view:

def start_task(request):

    get_external_user_info.delay(user=request.user)

    return HttpResponse("Task started")

But how do I do a ajax check if the task is completed?

Do I need another view? How would that view look like?

Tomas Jacobsen
  • 2,368
  • 6
  • 37
  • 81

1 Answers1

0

You have to get task_id

x= get_external_user_info.delay(user=request.user)
id = x.task_id
return HttpResponse(id)

After that using this id to ajax and get status

AsyncResult(id).state

Check this Celery task status

Community
  • 1
  • 1
anhlt
  • 384
  • 1
  • 4
  • 11