Re: how to handle database down time gracefully?
On Fri, Apr 24, 2009 at 7:51 AM, realfunwrote: > I build a website(fayaa.com) on Bluehost using Django, but this month > database down 3 times, during that period, user can only see an > "Unexpected Exception" message, is there a way to redirect to a 404 > page instead? If you don't mind doing things completely wrong, sure. "My database is broken and nothing on my site works" is not "file not found". It is and should always be "internal server error". Unless you'd rather have the embarrassment of people thinking there's nothing on your site to come back and see, as opposed to having them think it's down all the time. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to handle database down time gracefully?
This has been on my todo list of a while now, so I thought I'd trying to figure it out. I -think- the proper way to go about this would be in a custom middleware with a process_exception handler that checks to see if the exception is an instanace of the database defined exceptions. Looking in django/db/__init__.py shows "DatabaseError" gets assigned according to backend, so I assume it's safe to use as a check regardless of database settings. Turning off my database any playing I did a check on the exception generated when the database was down, and it looks ok - atleast for postgres: from django.db import DatabaseError isinstance(exception,DatabaseError) returned true. So I though I could add this method to a middleware class: def process_exception(self,request,exception): # In case django doesn't send use the original request from django.db import DatabaseError if isinstance(exception,DatabaseError): return HttpResponse("Database offline for maintenance - please try back later") return None Unfortunately, process_excpetion() never seems to get called. Searching track shows a ticket that explains the problem. Exceptions in middleware don't hit the middlware exception handlers. Unfortunately one of my middlware does hit the database on each call, so I had to modify my middlware to catch the exception and return a response object. http://code.djangoproject.com/ticket/6094 Other than making sure to handle any middlware DB exceptions manually it seems to be working ok. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to handle database down time gracefully?
On Friday 24 April 2009 04:51:54 am realfun wrote: > Hi, > > I build a website(fayaa.com) on Bluehost using Django, but this month > database down 3 times, during that period, user can only see an > "Unexpected Exception" message, is there a way to redirect to a 404 > page instead? > > Regards, > -realfun I've seen a settings option that is used as a check in other projects for such a situation. You can put the check in a custom middleware. In settings.py add something like this: # set to True to turn on maintaince page MAINTAINANCE = True and rewrite process_request to return the approriate response for a maintaince page based on the setting on a true setting or return None on a false setting, stating the site is going through maintainence or what ever message you want to tell them. http://docs.djangoproject.com/en/dev/topics/http/middleware/#process-request If you want to have the middleware check the availability of the db, I'm not exactly positive what you can check here in django.db, but possibly to check the connection, a thumb through django.db with ipython against a sqlite3 db, didn't show me a lot, but I also didn't go indepth into what each method is, for those I'm not 100% on. But this check, I'm not positive how big of a performance hit it would be or not, since this would be checked on each request. I've normally just set the maintaince flag manually when required. Mike -- Big book, big bore. -- Callimachus signature.asc Description: This is a digitally signed message part.
Re: how to handle database down time gracefully?
I'm interested as well. You'd want to have a 500 with a nice unexpected maintanence message. On Apr 24, 4:51 am, realfunwrote: > Hi, > > I build a website(fayaa.com) on Bluehost using Django, but this month > database down 3 times, during that period, user can only see an > "Unexpected Exception" message, is there a way to redirect to a 404 > page instead? > > Regards, > -realfun --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
how to handle database down time gracefully?
Hi, I build a website(fayaa.com) on Bluehost using Django, but this month database down 3 times, during that period, user can only see an "Unexpected Exception" message, is there a way to redirect to a 404 page instead? Regards, -realfun --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---