This repository has been archived by the owner on Feb 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
manager.py
78 lines (55 loc) · 1.68 KB
/
manager.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import logging
from time import sleep
from worker import Worker
import irc
import webui
from trackers import Trackers
thread_irc = None
thread_webui = None
trackers = None
logger = logging.getLogger("MANAGER")
logger.setLevel(logging.DEBUG)
def run():
global thread_irc, thread_webui, trackers
trackers = Trackers()
if len(trackers.loaded) <= 0:
logger.info("No trackers were initialized, exiting...")
quit()
thread_irc = irc_task(trackers)
thread_webui = webui_task(trackers)
thread_irc.fire('START')
thread_webui.fire('START')
thread_irc.wait_thread(thread_irc)
thread_webui.wait_thread(thread_webui)
logger.debug("Finished waiting for irc & webui threads")
############################################################
# Tasks
############################################################
def irc_task(trackers):
worker = Worker()
working = True
@worker.listen("START")
def _(event):
logger.debug("Start IRC Task signaled")
while working:
try:
irc.start(trackers)
except Exception as e:
logger.exception("Exception irc_task START: ")
sleep(30)
logger.debug("IRC Task finished")
return worker.start()
def webui_task(trackers):
worker = Worker()
working = True
@worker.listen("START")
def _(event):
logger.debug("Start WebUI Task signaled")
while working:
try:
webui.run(trackers)
except Exception as e:
logger.exception("Exception webui_task START: ")
sleep(30)
logger.debug("WebUI Task finished")
return worker.start()