18 from typing
import List, Callable
19 from threading
import Thread, Event, RLock
24 from ...logging
import Log
27 MAX_WAIT_TIME_BEFORE_UPDATE = 5
28 UploadFunction = Callable[[List[Log]], bool]
34 Not intended for outside use
36 A worker thread which is constantly running and
37 uploading logs to Coretex backend every 5 seconds
39 If the upload request fails the wait time is doubled
42 def __init__(self, uploadFunction: UploadFunction) ->
None:
46 self.setName(
"LoggerUploadWorker")
50 self.
__lock__lock = RLock()
51 self.
__waitTime__waitTime = MAX_WAIT_TIME_BEFORE_UPDATE
52 self.__pendingLogs: List[Log] = []
55 def isStopped(self) -> bool:
58 def stop(self) -> None:
62 def add(self, log: Log) ->
None:
67 self.__pendingLogs.append(log)
69 def uploadLogs(self) -> bool:
74 if len(self.__pendingLogs) == 0:
82 self.__pendingLogs.clear()
86 def run(self) -> None:
92 except BaseException
as exception:
93 logging.getLogger(
"coretexpylib").debug(
">> [Coretex] Failed to upload logs", exc_info = exception)
98 self.
__waitTime__waitTime = MAX_WAIT_TIME_BEFORE_UPDATE