Skip to content

Commit

Permalink
Trying to reconnect to db if cookie auth fails
Browse files Browse the repository at this point in the history
  • Loading branch information
wick3d committed Aug 22, 2010
1 parent e2b730f commit d22ac9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions midgardmvc/lib/midgard/auth/cookie.py
Expand Up @@ -167,6 +167,12 @@ def authenticate(self, environ, identity):

user = h.midgard.db.user.get({"login": identity.get("login"), "authtype": self.authtype})

if not user:
# Try to reopen db connection and then try again
from midgardmvc.lib.midgard.connection import instance as connection_instance
if connection_instance.reconnect():
user = h.midgard.db.user.get({"login": identity.get("login"), "authtype": self.authtype})

log.debug("user: ")
log.debug(user)

Expand Down
10 changes: 10 additions & 0 deletions midgardmvc/lib/midgard/connection.py
Expand Up @@ -55,6 +55,16 @@ def connect(self):
raise Exception('Could not open database connection, reason: %s' % midgard._connection.get_error_string())

return True

def reconnect(self):
try:
self._connected = self._connection.reopen()
except Exception, e:
print "Exception occurred while trying to reconnect: "
print e
self._connected = False

return self._connected

instance = ConnectionWrapper()

0 comments on commit d22ac9c

Please sign in to comment.