2

I have a desktop application that send POST requests to a server where a django app store the results. DB server and web server are not on the same machine and it happens that sometimes the connectivity is lost for a very short time but results in a connection error on some requests:

OperationalError: (2003, "Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (110)")

On a "normal" website I guess you'd not worry too much: the browser display a 500 error page and the visitor tries again later. In my case loosing info posted by a request is not an option and I am wondering how to handle this? I'd try to catch on this exception, wait for the connectivity to come back (lag is not a problem) and then continue the process. But as the exception can occur about anywhere in the code I'm a bit stuck on how to proceed.

Thanks for your advice.

4
  • Is the desktop application also a Django app? If not, why is this question tagged python/mysql/django? Please elaborate on the client-side stack. Commented Jun 7, 2012 at 11:03
  • No the desktop app is built with native code (C++) and is already deployed, nothing can be done on that side anymore (it would have been a better solution for sure). Isn't it possible to do something on the server now? Commented Jun 7, 2012 at 11:07
  • OK, you're talking about web server <-> DB connection, not desktop <-> web server connection. Got it. Commented Jun 7, 2012 at 11:09
  • Yes, the problem is the connection between the web server and the database server. Sorry if it wasn't clear. Commented Jun 7, 2012 at 11:11

2 Answers 2

1

You could make your own WSGI application that would decorate django's wsgi application, in yourproject/wsgi.py.

If your wsgi application decorator doesn't get an acceptable from the decorated application, it could wait a while and try again later.

But in reality, you should fix the client. The client should not expect to be connected to a working server 24/7. Until then I wouldn't thrust this desktop client as a user.

Sign up to request clarification or add additional context in comments.

Comments

1

You could use a middleware with a process_view method and a try / except wrapping your call.

Or you could decorate your views and wrap the call there.

Or you could use class based views with a base class that has a method decorator on its dispatch method, or an overriden.dispatch.

Really, you have plenty of solutions.

Now, as said above, you might want to modify your Desktop application too!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.