From a101542bc203098cc5848630115e34fc1c747075 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sat, 3 Oct 2020 00:44:55 +0200 Subject: [PATCH] Do not import gun data if sequence has no shots. Doing otherwise will result in the gun data file appearing has having been read, but no data will have been saved as there was nowhere to save to. Fixes #29. --- bin/datastore.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bin/datastore.py b/bin/datastore.py index bc0c030..e010dd5 100644 --- a/bin/datastore.py +++ b/bin/datastore.py @@ -483,6 +483,21 @@ class Datastore: #self.del_hash("*online*", cursor) # The shots should already exist, e.g., from a P1 import + # …but what about if the SMSRC file gets read *before* the P1? + # We need to check + qry = "SELECT count(*) FROM raw_shots WHERE sequence = %s;" + values = (fileinfo["sequence"],) + cursor.execute(qry, values) + shotcount = cursor.fetchone()[0] + if shotcount == 0: + # No shots yet or not all imported, so we do *not* + # save the gun data. It will eventually get picked + # up in the next run. + # Let's remove the file from the file list and bail + # out. + print("No raw shots for sequence", fileinfo["sequence"]) + self.conn.rollback() + return values = [ (json.dumps(record), fileinfo["sequence"], record["shot"]) for record in records ]