-
Notifications
You must be signed in to change notification settings - Fork 1
/
manager.py
55 lines (48 loc) · 1.49 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
#coding=utf8
'''
Created on 2017-6-6
@author: xuwei
@summary: 任务管理器
'''
import time
import tasks
from timer import Wheel
from timer.logger import Logger
class TaskManager(Logger):
def __init__(self):
Logger.__init__(self)
self.tasks = {}
self.Wheel = Wheel()
def load_task(self):
reload(tasks)
for taskname in tasks.runtasks:
if taskname not in self.tasks:
try:
self.tasks[taskname] = tasks.runtasks[taskname]
module = __import__(taskname)
self.Wheel.add_task(module, taskname, **tasks.runtasks[taskname])
except:
errmsg = self.get_error_message()
self.logger.error(errmsg)
time.sleep(3)
else:
if self.tasks[taskname] != tasks.runtasks[taskname]:
try:
self.Wheel.update_time(taskname, **tasks.runtasks[taskname])
except:
errmsg = self.get_error_message()
self.logger.error(errmsg)
def run(self):
self.load_task()
self.Wheel.start()
time.sleep(10)
while 1:
try:
self.load_task()
except:
errmsg = self.get_error_message()
self.logger.error(errmsg)
time.sleep(10)
if __name__ == "__main__":
TS = TaskManager()
TS.run()