Skip to content

Commit

Permalink
Threading dict now has error handling when updater function crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
RedRem95 committed Apr 2, 2024
1 parent 8a3f3f4 commit ea9ace3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion clickup_to_ical/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.7"
__version__ = "0.0.8"
6 changes: 3 additions & 3 deletions clickup_to_ical/web/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {}
Expand All @@ -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,
Expand Down
15 changes: 10 additions & 5 deletions clickup_to_ical/web/utils.py
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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()
Expand Down

0 comments on commit ea9ace3

Please sign in to comment.