Aikanáro
Aikanáro

Reputation: 849

Nginx/Gunicorn timeout when running query that takes 2+ minutes to complete on django

I'm running a query that takes maximum 3 minutes to complete with django, using connections['report'].cursor()

When I make a request to the view that execute that query, Nginx give me a timeout (that is presented in the view as "502 Bad Gateway").

What approach should I choose to overcome this issue? Should I increase the timeout setting or how can I make this asynchronous?

Upvotes: 0

Views: 538

Answers (1)

Jahongir Rahmonov
Jahongir Rahmonov

Reputation: 13733

First approach (easiest): You can increase the timeout setting. This way your users will have to wait a long time. Not a good user experience.

Second approach (moderate difficulty): If your users don't have to wait for that request (such as email sending), you could delegate that task to a background worker. In Django community, that's usually done by celery

Third approach (the most difficult - best experience): Use django-channels and web sockets. This will take a lot of time if you are new to these technologies.

Choose depending on your case. Hope it helps!

Upvotes: 3

Related Questions