[Reproducible-commits] [misc] 01/01: clean-notes: use the same udd functions jenkins uses, they do a lot of error checks and don't choke when udd is down. also it timeouts quicker

Mattia Rizzolo mattia at mapreri.org
Mon Aug 17 11:06:14 UTC 2015


This is an automated email from the git hooks/post-receive script.

mapreri-guest pushed a commit to branch master
in repository misc.

commit c8c414f3b648a667d35da9e3519cdc87ff0bfc45
Author: Mattia Rizzolo <mattia at mapreri.org>
Date:   Mon Aug 17 11:06:09 2015 +0000

    clean-notes: use the same udd functions jenkins uses, they do a lot of error checks and don't choke when udd is down. also it timeouts quicker
---
 clean-notes | 52 +++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/clean-notes b/clean-notes
index e0bf115..820e74a 100755
--- a/clean-notes
+++ b/clean-notes
@@ -155,22 +155,52 @@ def start_udd_connection():
     port = 5432
     db = "udd"
     try:
-        log.debug("Starting connection to the UDD database")
-        conn = psycopg2.connect("dbname=" + db +
-                                " user=" + username +
-                                " host=" + host +
-                                " port=" + str(port) +
-                                " password=" + password)
+        try:
+            log.debug("Starting connection to the UDD database")
+            conn = psycopg2.connect(
+                database=db,
+                user=username,
+                host=host,
+                password=password,
+                connect_timeout=5,
+            )
+        except psycopg2.OperationalError as err:
+            if str(err) == 'timeout expired\n':
+                log.error('Connection to the UDD database replice timed out. '
+                          'Maybe the machine is offline or just unavailable.')
+                log.error('Failing nicely anyway, all queries will return an '
+                          'empty response.')
+                return None
+            else:
+                raise
     except:
-        log.error("Error connecting to the UDD database replica")
-        raise
+        log.error('Erorr connecting to the UDD database replica.' +
+                  'The full error is:')
+        exc_type, exc_value, exc_traceback = sys.exc_info()
+        print_exception(exc_type, exc_value, exc_traceback)
+        log.error('Failing nicely anyway, all queries will return an empty ' +
+                  'response.')
+        return None
     conn.set_client_encoding('utf8')
     return conn
 
 
 def query_udd(query):
-    cursor = conn.cursor()
-    cursor.execute(query)
+    if not conn_udd:
+        log.error('There has been an error connecting to the UDD database. ' +
+                  'Please look for a previous error for more information.')
+        log.error('Failing nicely anyway, returning an empty response.')
+        return []
+    cursor = conn_udd.cursor()
+    try:
+        cursor.execute(query)
+    except:
+        log.error('The UDD server encountered a issue while executing the ' +
+                  'query. The full error is:')
+        exc_type, exc_value, exc_traceback = sys.exc_info()
+        print_exception(exc_type, exc_value, exc_traceback)
+        log.error('Failing nicely anyway, returning an empty response.')
+        return []
     return cursor.fetchall()
 
 
@@ -444,7 +474,7 @@ if __name__ == '__main__':
     if 'not-usertagged' not in args.disable or \
        'missing-usertagged' not in args.disable or \
        'archived-bugs' not in args.disable:
-        conn = start_udd_connection()
+        conn_udd = start_udd_connection()
     notes = load_notes()
     if not args.sort_only:
         testedpkgs = load_reproducible_status()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/misc.git



More information about the Reproducible-commits mailing list