From ea9ace397f78855fa662dc452d21bbad515e44ee Mon Sep 17 00:00:00 2001 From: RedRem95 Date: Tue, 2 Apr 2024 18:52:20 +0200 Subject: [PATCH] Threading dict now has error handling when updater function crashes --- clickup_to_ical/__init__.py | 2 +- clickup_to_ical/web/stores.py | 6 +++--- clickup_to_ical/web/utils.py | 15 ++++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/clickup_to_ical/__init__.py b/clickup_to_ical/__init__.py index 6526deb..a73339b 100644 --- a/clickup_to_ical/__init__.py +++ b/clickup_to_ical/__init__.py @@ -1 +1 @@ -__version__ = "0.0.7" +__version__ = "0.0.8" diff --git a/clickup_to_ical/web/stores.py b/clickup_to_ical/web/stores.py index 452276c..2d106d5 100644 --- a/clickup_to_ical/web/stores.py +++ b/clickup_to_ical/web/stores.py @@ -11,7 +11,7 @@ def _update_auth(): import json if "AUTH_FILE" in os.environ: with open(os.environ["AUTH_FILE"], "r") as f_in: - _LOGGER.info("Read new auth file") + _LOGGER.debug("Read new auth file") return json.load(f_in) return None @@ -23,7 +23,7 @@ def _update_default_length(): import json if "DEFAULT_LENGTH" in os.environ: with open(os.environ["DEFAULT_LENGTH"], "r") as f_in: - _LOGGER.info("Read new default length for events file") + _LOGGER.debug("Read new default length for events file") return json.load(f_in) else: return {} @@ -37,7 +37,7 @@ def _update_tasks(): from datetime import timedelta from clickup_to_ical.clickup import get_tasks_all from collections import defaultdict - _LOGGER.info("Updating tasks") + _LOGGER.debug("Updating tasks") t1 = perf_counter() _tasks = get_tasks_all( with_closed=os.environ.get("TASKS_CLOSED", "") in TRUE_VALUES, diff --git a/clickup_to_ical/web/utils.py b/clickup_to_ical/web/utils.py index eb045f4..e253393 100644 --- a/clickup_to_ical/web/utils.py +++ b/clickup_to_ical/web/utils.py @@ -1,12 +1,14 @@ import threading import time -from threading import Lock +from logging import getLogger from typing import Tuple, Callable +_LOGGER = getLogger("clickup_to_ical") + class ThreadingDict: def __init__(self, auto_update: Tuple[Callable[[], dict], int] = None): - self._lock = Lock() + self._lock = threading.Lock() self._data = {} if auto_update is not None: fn = auto_update[0] @@ -15,9 +17,12 @@ def __init__(self, auto_update: Tuple[Callable[[], dict], int] = None): def _tmp(): while True: - _v = fn() - if _v is not None: - self.set(_v) + try: + _v = fn() + if _v is not None: + self.set(_v) + except Exception as e: + _LOGGER.exception("Failed to update", e) time.sleep(freq) threading.Thread(target=_tmp, daemon=True).start()