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

This commit is contained in:
Sergi Delgado Segura
2020-01-22 15:20:50 +01:00
parent 1027f48611
commit fd6c85ced2
2 changed files with 10 additions and 1 deletions

View File

@@ -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)

View File

@@ -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)