Timeout when saving model in django admin page

267 views
Skip to first unread message

John, Steffen

unread,
Feb 21, 2017, 5:02:17 AM2/21/17
to django...@googlegroups.com
Hi!

When saving the model over the admin page of Django, a lot of processing is done (in pre_save function) which takes several minutes. After a while I get a timeout, although the process is still running in the background.

How can I avoid to get this timeout?

Another nice thing would be to show the progress of the saving process, may be with a progress bar. Do you have any ideas/hints/links on how to do that?

Thank you in advance!

Steffen

Jani Tiainen

unread,
Feb 21, 2017, 6:55:26 AM2/21/17
to django...@googlegroups.com

Hi,

You probably want to switch to asynchronous handling of your job.

Celery is one excellent tool to handle background jobs.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1487670629.2604.6.camel%40atenekom.eu.
For more options, visit https://groups.google.com/d/optout.

-- 
Jani Tiainen

John, Steffen

unread,
Feb 21, 2017, 8:11:46 AM2/21/17
to django...@googlegroups.com
Hi,
Thanks for the hint. I was already thinking about using celery, but if the process runs in background it may get some problems with other actions the user executes parallely.

Using celery, is it possible to prevent the user from doing other things in the admin tool until the celery task is done?

thanks,
Steffen 

Melvyn Sopacua

unread,
Feb 21, 2017, 8:45:38 AM2/21/17
to django...@googlegroups.com

On Tuesday 21 February 2017 13:11:19 John, Steffen wrote:

 

> Using celery, is it possible to prevent the user from doing other

> things in the admin tool until the celery task is done?

 

Sorta kinda.

But the django admin can facilitate part of it. Look into the ModelAdmin.has_FOO_permission() methods. These get passed the request. So you could implement something like:

 

- set has_job_running on User profile model

- for possibly dangerous actions, return false for the has_FOO_permission() method if request.user.profile.has_job_running is True.

- on job end, reset the user's has_job_running flag.

 

You can refine this to a tee, with different completion stages for the job opening up otherwise denied actions, etc etc.

 

The timeout however, is something with your webserver / wsgi implementation and you should look there. For example, nginx has several timeouts for handling a WSGI request that come into play. Increasing those, also means you tie up resources and are more succeptable to denial of service, so if celery is an option, take it.

 

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages