From f3b7ffb3a1bc6732a5075efa2e71589aa2553583 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 13 Feb 2023 20:45:05 +0000 Subject: [PATCH] Bump to 0.1.7-test --- Dockerfile | 2 +- src/main.py | 2 +- src/mongo.py | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index ede9747..1fceb50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,4 @@ FROM python:3.11-alpine COPY ./requirements.txt /app/requirements.txt RUN [ "pip", "install", "-r", "/app/requirements.txt" ] COPY ./src /app/src -ENTRYPOINT [ "python", "/app/src/test.py" ] \ No newline at end of file +CMD [ "python", "/app/src/main.py" ] \ No newline at end of file diff --git a/src/main.py b/src/main.py index 204e531..8c1f77a 100644 --- a/src/main.py +++ b/src/main.py @@ -14,7 +14,7 @@ # program. If not, see # https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE -version = "0.1.0" +version = "0.1.7" print(f"main.py: Initialising db-manager v{version}") #Third Party Imports diff --git a/src/mongo.py b/src/mongo.py index 44f527d..2cde168 100644 --- a/src/mongo.py +++ b/src/mongo.py @@ -18,12 +18,12 @@ db = client[db_name] def metaCheckTime(target): col = db["meta"] res = col.find_one({"target": target, "type": "collection"}) - if 'updated' in res: + if type(res) is dict: + if 'updated' in res: log.out(f'mongo.metaUpdateTime: {target} last updated at {res["updated"]}', "INFO") return res["updated"] - else: - log.out(f'mongo.metaUpdatetime: {target} does not exist', "INFO") - return 0 + log.out(f'mongo.metaUpdatetime: {target} does not exist', "INFO") + return 0 def metaUpdateTime(target): col = db["meta"] @@ -82,9 +82,11 @@ def metaCounters(): collection = "meta" col = db[collection] res = col.find_one({"target": "counters","type": "count"}) - if 'since' not in res: - log.out('mongo.metaCounters: counters does not exist, creating', "INFO") - col.update_one({"target": "counters","type": "count"}, {"target": "counters","type": "count","since": int(time.time())}) - else: + log.out(f'mongo.metaCounters: Query returned `{res}`', "DEBG") + if type(res) is dict: + if 'since' in res: log.out('mongo.metaCounters: counters already exists, skipping', "INFO") + return + log.out('mongo.metaCounters: counters does not exist, creating', "INFO") + col.update_one({"target": "counters","type": "count"}, {"$set":{"target": "counters","type": "count","since": int(time.time())}}, upsert=True) return \ No newline at end of file