Skip to content
Snippets Groups Projects
Commit 730ad55e authored by Robert Goldmann's avatar Robert Goldmann
Browse files

added CachedService

parent 5dacb367
Branches
No related tags found
No related merge requests found
import abc
from abc import ABC
from datetime import datetime
from typing import Dict
class CachedService(ABC):
def __init__(self, fetchThresholdInSeconds: int):
self._fetchThresholdInSeconds = fetchThresholdInSeconds
self._lastFetchTimestamp = 0
self._data = None
def get_data(self) -> Dict:
if self.__is_data_obsolete():
self._data = self._fetch_data()
return self._data
def __is_data_obsolete(self) -> bool:
now = datetime.now().timestamp()
if (now - self._lastFetchTimestamp) > self._fetchThresholdInSeconds:
self._lastFetchTimestamp = now
return True
self._lastFetchTimestamp = now
return False
@abc.abstractmethod
def _fetch_data(self) -> Dict:
pass
from PythonLibs.DefaultLogger import DefaultLogger
from PythonLibs.MailHandler import MailHandler
from PythonLibs.CachedService import CachedService
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment