From 97104556b766259873aae71482ee31f0fdca1451 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Wed, 23 Sep 2020 15:46:17 +0200 Subject: [PATCH] Do not hard fail if imports fail for one project. It may be the case that we have already re-imported some of the data, so we just move on to the next project. --- bin/system_imports.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bin/system_imports.py b/bin/system_imports.py index 925aa4d..1cd16a0 100755 --- a/bin/system_imports.py +++ b/bin/system_imports.py @@ -9,7 +9,7 @@ import os from glob import glob import configuration import preplots -from datastore import Datastore +from datastore import Datastore, psycopg2 exportables = [ "events_seq", @@ -38,11 +38,14 @@ if __name__ == '__main__': print("Survey does not define an export path for machine data") continue - for table in exportables: - path = os.path.join(pathPrefix, table) - print(" ← ", path, " → ", table) - with open(path, "rb") as fd: - cursor.copy_from(fd, table); + try: + for table in exportables: + path = os.path.join(pathPrefix, table) + print(" ← ", path, " → ", table) + with open(path, "rb") as fd: + cursor.copy_from(fd, table); + except psycopg2.errors.UniqueViolation: + print("It looks like data for this survey may have already been imported (unique constraint violation)") # If we don't commit the data does not actually get copied db.conn.commit()