Commit f8efe257 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

reconnect to DB after plot generation

parent 8f6a1d2f
......@@ -272,7 +272,7 @@ def main(argv):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
ret = p.wait()
if ret != 0:
logger.error("Observer %d (%s) appears to be offline." % (int(obs[0]), obs[1]))
logger.warning("Observer %d (%s) appears to be offline." % (int(obs[0]), obs[1]))
if obs[2] == 'online':
cur.execute("UPDATE `tbl_serv_observer` SET status='offline' WHERE observer_id=%d" % int(obs[0]))
cn.commit()
......
......@@ -1450,13 +1450,7 @@ def main(argv):
starttime = time.time()
errors, warnings = stop_test(testid, cur, cn, obsdict_key, obsdict_id, abort)
# Close and reopen the DB connection (if stop test takes longer than usual, the DB connection might get dropped by the server)
try:
cur.close()
cn.close()
except:
pass
(cn, cur) = flocklab.connect_to_db()
(cn, cur) = flocklab.check_db_connection(cn, cur)
# Record time needed to set up test for statistics in DB:
time_needed = time.time() - starttime
......@@ -1508,6 +1502,7 @@ def main(argv):
err = prepare_testresults(testid, cur)
for e in err:
errors.append(e)
(cn, cur) = flocklab.check_db_connection(cn, cur)
# Evaluate link measurement:
err = evaluate_linkmeasurement(testid, cur)
cn.commit()
......
......@@ -200,6 +200,22 @@ def connect_to_db():
### END connect_to_db()
##############################################################################
#
# check_db_connection - check connection to the database and reconnect if necessary
#
##############################################################################
def check_db_connection(conn, cursor):
try:
# arbitrary dummy request
cur.execute("SELECT * FROM `tbl_serv_observers` LIMIT 1")
except:
# reconnect
return connect_to_db()
return (conn, cursor)
### END connect_to_db()
##############################################################################
#
# is_user_admin - Check if a user ID belongs to an admin.
......
Supports Markdown
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