diff --git a/database.py b/database.py index 3595bab..4f7605f 100644 --- a/database.py +++ b/database.py @@ -930,6 +930,7 @@ def sync(): # all entries by file collected # so we don't open the same file for every entry + log("Syncing",module="debug") entries = {} for idx in range(len(SCROBBLES)): @@ -949,11 +950,15 @@ def sync(): SCROBBLES[idx] = (SCROBBLES[idx][0],SCROBBLES[idx][1],True) + log("Sorted into months",module="debug") + for e in entries: tsv.add_entries("scrobbles/" + e + ".tsv",entries[e],comments=False) #addEntries("scrobbles/" + e + ".tsv",entries[e],escape=False) utilities.combineChecksums("scrobbles/" + e + ".tsv",cla.checksums) + log("Written files",module="debug") + global lastsync lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) diff --git a/server.py b/server.py index 3d6a3f2..b258bd2 100755 --- a/server.py +++ b/server.py @@ -68,7 +68,11 @@ def customerror(error): def graceful_exit(sig=None,frame=None): #urllib.request.urlopen("http://[::1]:" + str(DATABASE_PORT) + "/sync") - database.sync() + log("Received signal to shutdown") + try: + database.sync() + except Exception as e: + log("Error while shutting down!",e) log("Server shutting down...") os._exit(42)