Prashant Pandey
Prashant Pandey

Reputation: 241

How to put an api into celery task in django?

I am using Django, celery, and DjangoRestFramework for APIs. I have an API that takes around 1 minute to show data in JSON format. The problem is Heroku ( server) shows application error if a function takes more than 30 seconds. Hence I want to put my API into celery tasks. Please suggest the way to do so.

Upvotes: 2

Views: 1862

Answers (1)

Umair Mohammad
Umair Mohammad

Reputation: 4635

Maybe you can do something like this :

  1. GET/POST/etc come to a particular end-point

  2. View attached to url is activated

  3. Here you can start/initialize the celery task and return the job id (investigation needed on this id part, I guess celery task return some EagerResult or something syncronously/ you can implement custom job id feature)

  4. User gets the job id for there particular request

5 User can make another request after some delay using that id

  1. If that celery tasks is completed then return result based on job id

This is just an overview of my initial thoughts. Much thoughts, refinement required.

Lemme know your thoughts.

Upvotes: 3

Related Questions