From fd6c85ced22108c4332112134b769eb6c2872151 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 22 Jan 2020 15:20:50 +0100 Subject: [PATCH] Moves logs to be consistent with the rest of db logs. Adds missing docs and adds an exception if the db is alredy being used --- pisa/cleaner.py | 1 - pisa/db_manager.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pisa/cleaner.py b/pisa/cleaner.py index 37480a6..75ea322 100644 --- a/pisa/cleaner.py +++ b/pisa/cleaner.py @@ -148,7 +148,6 @@ class Cleaner: """ for uuid in triggered_appointments: - logger.info("Flagging appointment as triggered", locator=appointments[uuid].get("locator"), uuid=uuid) Cleaner.delete_appointment_from_memory(uuid, appointments, locator_uuid_map) db_manager.create_triggered_appointment_flag(uuid) diff --git a/pisa/db_manager.py b/pisa/db_manager.py index 4670215..2c693b6 100644 --- a/pisa/db_manager.py +++ b/pisa/db_manager.py @@ -30,6 +30,10 @@ class DBManager: Args: db_path (:obj:`str`): the path (relative or absolute) to the system folder containing the database. A fresh database will be create if the specified path does not contain one. + + Raises: + ValueError: If the provided ``db_path`` is not a string. + plyvel.Error: If the db is currently unavailable (being used by another process). """ def __init__(self, db_path): @@ -44,6 +48,10 @@ class DBManager: logger.info("No db found. Creating a fresh one") self.db = plyvel.DB(db_path, create_if_missing=True) + elif "LOCK: Resource temporarily unavailable" in str(e): + logger.info("The db is already being used by another process (LOCK)") + raise e + def load_appointments_db(self, prefix): """ Loads all data from the appointments database given a prefix. Two prefixes are defined: ``WATCHER_PREFIX`` and @@ -371,6 +379,7 @@ class DBManager: """ self.db.put((TRIGGERED_APPOINTMENTS_PREFIX + uuid).encode("utf-8"), "".encode("utf-8")) + logger.info("Flagging appointment as triggered", uuid=uuid) def load_all_triggered_flags(self): """ @@ -394,3 +403,4 @@ class DBManager: """ self.delete_entry(uuid, prefix=TRIGGERED_APPOINTMENTS_PREFIX) + logger.info("Removing triggered flag from appointment appointment", uuid=uuid)