#logger.debug("INSERT INTO jenkins_job(name) VALUES('%s')" % (name))
return cur.fetchone()[0]
+def harmonize_timeformat(time)
+ if time != 'NULL':
+ if time.isdigit():
+ time = "to_timestamp('%s')" % time
+ else:
+ time = "'%s'" % time
+ return time
+
def db_add_build(con, db_id, number, start, end, status):
cur = con.cursor()
cur.execute("SAVEPOINT a")
- if start != 'NULL' and start.isdigit():
- start = "to_timestamp('%s')" % start
- if end != 'NULL' and end.isdigit():
- end = "to_timestamp('%s')" % end
+ start = harmonize_timeformat(start)
+ end = harmonize_timeformat(end)
try:
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()
def db_update_build(con, db_id, end, status):
cur = con.cursor()
cur.execute("SAVEPOINT a")
- if end != 'NULL' and end.isdigit():
- end = "to_timestamp('%s')" % end
+ logger.debug('end = %s' % end)
+ end = harmonize_timeformat(end)
+ logger.debug('harmonized_end = %s' % end)
try:
- cur.execute("UPDATE jenkins_build SET build_end = '%s', status = '%s' WHERE id = %s RETURNING id" % (end, status, db_id))
+ cur.execute("UPDATE jenkins_build SET build_end = %s, status = '%s' WHERE id = %s RETURNING id" % (end, status, db_id))
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" % (end, status, db_id))
+ logger.debug("UPDATE jenkins_build SET build_end = %s, status = '%s' WHERE id = %s RETURNING id" % (end, status, db_id))
return cur.fetchone()[0]
def db_add_origin(con, origin):