-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathscheduled.py
34 lines (27 loc) · 1.14 KB
/
scheduled.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import threading
import time
import structlog
import codegate
from codegate.updates.client import Origin, UpdateClient
logger = structlog.get_logger("codegate")
class ScheduledUpdateChecker(threading.Thread):
"""
ScheduledUpdateChecker calls the UpdateClient on a recurring interval.
This is implemented as a separate thread to avoid blocking the main thread.
A dedicated scheduling library could have been used, but the requirements
are trivial, and a simple hand-rolled solution is sufficient.
"""
def __init__(self, client: UpdateClient, interval_seconds: int = 14400): # 4 hours in seconds
super().__init__()
self.__client = client
self.__interval_seconds = interval_seconds
def run(self):
"""
Overrides the `run` method of threading.Thread.
"""
while True:
logger.info("Checking for CodeGate updates")
latest = self.__client.get_latest_version(Origin.BackEnd)
if latest != codegate.__version__:
logger.warning(f"A new version of CodeGate is available: {latest}")
time.sleep(self.__interval_seconds)