-
Notifications
You must be signed in to change notification settings - Fork 77
/
updater.py
40 lines (33 loc) · 1.22 KB
/
updater.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
35
36
37
38
39
40
import threading
from queue import Queue
import logging
import time
from asu.utils.config import Config
from asu.utils.database import Database
from asu.utils.worker import Worker
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)
class Updater(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.log = logging.getLogger(__name__)
self.config = Config()
self.database = Database(self.config)
self.update_queue = Queue(1)
def run(self):
location = self.config.get("updater_dir", "updater")
Worker(location, None, None).setup_meta()
workers = []
# start all workers
for i in range(0, self.config.get("updater_threads", 4)):
log.info("starting updater thread {}".format(i))
worker = Worker(location, "update", self.update_queue)
worker.start()
workers.append(worker)
while True:
outdated_target = self.database.get_outdated_target()
if outdated_target:
log.info("found outdated target %s", outdated_target)
self.update_queue.put(outdated_target)
else:
time.sleep(5)