From: Holger Levsen Date: Fri, 12 Oct 2012 12:34:02 +0000 (+0200) Subject: fixup fixup and add some more con_commits for savety X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=c8f6acfa80424d9bc366d78bcdd0c0a51ee7029e;p=profitbricks%2Fjenkins-build-scripts.git fixup fixup and add some more con_commits for savety --- diff --git a/db_add.py b/db_add.py index 64e5698..0b04c23 100755 --- a/db_add.py +++ b/db_add.py @@ -21,22 +21,27 @@ def db_add_job(con, name): cur.execute("SAVEPOINT a") try: cur.execute("INSERT INTO jenkins_job(name) VALUES('%s') RETURNING id" % (name)) + con.commit() except psycopg2.DatabaseError as e: # record already exist cur.execute("ROLLBACK TO a") # have to rollback after failed command cur.execute("SELECT id FROM jenkins_job WHERE name='%s'" % (name)) #logger.debug("INSERT INTO jenkins_job(name) VALUES('%s')" % (name)) - con.commit() return cur.fetchone()[0] def db_add_build(con, db_id, number, start, end, status): cur = con.cursor() cur.execute("SAVEPOINT a") + if start != 'NULL': + start = "to_timestamp('%s')" % start + if end != 'NULL': + end = "to_timestamp('%s')" % end try: - cur.execute("INSERT INTO jenkins_build(jenkins_job_id, jenkins_build_number, build_start, build_end, status) VALUES(%s, %s, to_timestamp('%s'), to_timestamp('%s'), '%s') RETURNING id" % (db_id, number, start, end, status)) + cur.execute("INSERT INTO jenkins_build(jenkins_job_id, jenkins_build_number, build_start, build_end, status) VALUES(%s, %s, %s, %s, '%s') RETURNING id" % (db_id, number, start, end, status)) + con.commit() except psycopg2.DatabaseError as e: cur.execute("ROLLBACK TO a") # have to rollback after failed command - logger.debug("INSERT INTO jenkins_build(jenkins_job_id, jenkins_build_number, build_start, build_end, status) VALUES(%s, %s, to_timestamp('%s'), to_timestamp('%s'), '%s') RETURNING id" % (db_id, number, start, end, status)) + logger.debug("INSERT INTO jenkins_build(jenkins_job_id, jenkins_build_number, build_start, build_end, status) VALUES(%s, %s, %s, %s, '%s') RETURNING id" % (db_id, number, start, end, status)) return cur.fetchone()[0] def db_update_build(con, db_id, end, status): @@ -44,6 +49,7 @@ def db_update_build(con, db_id, end, status): cur.execute("SAVEPOINT a") try: cur.execute("UPDATE jenkins_build SET build_end = '%s', status = '%s' WHERE id = %s RETURNING id" % (db_id, end, status)) + con.commit() except psycopg2.DatabaseError as e: cur.execute("ROLLBACK TO a") # have to rollback after failed command logger.debug("UPDATE jenkins_build SET build_end = '%s', status = '%s' WHERE id = %s RETURNING id" % (db_id, end, status)) @@ -54,7 +60,8 @@ def db_add_origin(con, origin): cur.execute("SAVEPOINT a") try: cur.execute("INSERT INTO deb_package_origin(origin) VALUES('%s') RETURNING id" % (origin)) - except psycopg2.DatabaseError as e: + con.commit() + except psycopg2.DatabaseError as e: # record already exist cur.execute("ROLLBACK TO a") # have to rollback after failed command cur.execute("SELECT id FROM deb_package_origin WHERE origin='%s'" % (origin)) @@ -66,6 +73,7 @@ def db_add_package(con, package): cur.execute("SAVEPOINT a") try: cur.execute("INSERT INTO deb_package(name) VALUES('%s') RETURNING id" % (package)) + con.commit() except psycopg2.DatabaseError as e: # record already exist cur.execute("ROLLBACK TO a") # have to rollback after failed command @@ -78,6 +86,7 @@ def db_add_package_instance(con, package_id, origin_id, build_id, version): cur.execute("SAVEPOINT a") try: cur.execute("INSERT INTO deb_package_instance(deb_package_id, deb_package_origin_id, jenkins_build_id, version, available) VALUES(%s, %s, %s, '%s', true) RETURNING id" % (package_id, origin_id, build_id, version)) + con.commit() except psycopg2.DatabaseError as e: # record already exist - this MUST NOT HAPPEN for jenkins builds cur.execute("ROLLBACK TO a") # have to rollback after failed command @@ -134,6 +143,7 @@ def db_add_requested_liveboot_build (con, request_id, build_id): cur.execute("SAVEPOINT a") try: cur.execute("INSERT INTO liveboot_request_jenkins_build(liveboot_request_id, jenkins_build_id) VALUES(%s, %s) RETURNING id" % (request_id, build_id)) + con.commit() except psycopg2.DatabaseError as e: cur.execute("ROLLBACK TO a") # have to rollback after failed command #logger.debug("INSERT INTO jenkins_build(jenkins_build_number, jenkins_job_id) VALUES(%s, %s) RETURNING id" % (number, db_id))