I am developing a project using django - python, javascript. When I call a long running process (time-consuming) approx more than 20 minutes from views the process starts successfully. I used loader in ajax to notify user that process is running. After the process completes the loader will stop and change to completed state.
But the issue is every time after 14.59 minutes from process started, the loader stops and status change to completed. But the process running in background is not yet completed. The page crash after that time. After the process complete I bind the result under a tag in web page. In that tag the error 504 (Gateway Timeout) arise. In web console log Failed to load resource: the server responded with a status of 504 (Gateway Timeout), the above error prints. If anyone knows please help me to fix this.
Is the django is closing the connection after that time ? If so is there possible to mention timeout in django settings (settings.py). I tried giving timeout in ajax call but the same issue returns. My doubt is on django development server. Is there timeout in django development server. But when I search for this issue I found, in nginx server the same type of issue arise. Is django depend on nginx or using it ?
I tried to provide all information regarding my issue if any further clarifications, please let me know.
The server always closes its connection after a particular amount of time, which can be modified by changing its configuration, but that would not be a good approach. I would suggest you to try to reduce time taken by the script by:
Also you should handle the timeout of the ajax call:
$.ajax({
...
timeout: 1000,
error: function(jqXHR, textStatus, errorThrown) {
if(textStatus==="timeout") {
//do something on timeout / show appropriate message.
}
}
});
References for tweaking performance and optimizing coding techniques thus reducing time: https://docs.djangoproject.com/en/1.10/topics/db/optimization/ https://docs.djangoproject.com/en/1.10/topics/performance/ https://realpython.com/blog/python/caching-in-django-with-redis/