Commit d6bc8627 authored by Jonathan Schaeffer's avatar Jonathan Schaeffer

More gracefull exception handling in psycopg2

parent 4f22f3e4
......@@ -159,31 +159,25 @@ def cleanup():
rows_deleted = cur.rowcount
conn.commit()
conn.close()
except Exception as e:
logging.error("Unable to connect to database %s as %s@%s:%s"%(application.config['AUTHDBNAME'],
application.config['AUTHDBUSER'],
application.config['AUTHDBHOST'],
application.config['AUTHDBPORT']))
except psycopg2.Error as e:
logging.error(e.pgerror)
raise e
try:
conn = psycopg2.connect(dbname= application.config['PRIVILEGEDBNAME'],
port = application.config['PRIVILEGEDBPORT'],
host = application.config['PRIVILEGEDBHOST'],
user= application.config['PRIVILEGEDBUSER'],
password = application.config['PRIVILEGEDBPASSWORD'])
cur = conn.cursor()
logging.debug("Connected to privlieges database")
logging.debug("Deleting from privileges database: %s", old_users)
cur.execute("delete from eida_temp_users where expires_at < now();")
conn.commit()
conn.close()
except Exception as e:
logging.error("Unable to connect to database %s as %s@%s:%s"%(application.config['PRIVILEGEDBNAME'],
application.config['PRIVILEGEDBUSER'],
application.config['PRIVILEGEDBHOST'],
application.config['PRIVILEGEDBPORT']))
raise e
try:
conn = psycopg2.connect(dbname= application.config['PRIVILEGEDBNAME'],
port = application.config['PRIVILEGEDBPORT'],
host = application.config['PRIVILEGEDBHOST'],
user= application.config['PRIVILEGEDBUSER'],
password = application.config['PRIVILEGEDBPASSWORD'])
cur = conn.cursor()
logging.debug("Connected to privlieges database")
logging.debug("Deleting from privileges database")
cur.execute("delete from eida_temp_users where expires_at < now();")
conn.commit()
conn.close()
except Exception as e:
logging.error(e.pgerror)
raise e
return Response("Deleted %d expired accounts."%(rows_deleted), status=200)
@application.route("/", methods=['POST'])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment