-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathtaskSchedule.py
66 lines (58 loc) · 1.65 KB
/
taskSchedule.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
#coding=utf-8
'''
nohup python taskSchedule.py &
'''
import os
import sys
import time
import json
import datetime
import teye_config as Settings
from LogManager import log
from Queue import Queue
from teye_worker.RDB import RDB
from teye_worker.scan import DoScanTask
WAT_MSG_INFO={"taskid":"","website":"","profile":"","message":""}
if __name__=='__main__':
'''
'''
q = Queue(Settings.MAX_DISPATCH_TASK)
while True:
while True:
count = 0
try:
rdb = RDB()
rdb.connect()
tasks =rdb.getNewtasks(Settings.MAX_DISPATCH_TASK)
for task in tasks:
msg= task.get("msg")
taskid=task.get("taskid")
taskstarttime = datetime.datetime.now()
rdb.updateFlag(taskid)
rdb.updateStart(taskid,taskstarttime)
q.put(msg)
rdb.close()
break
except Exception,e:
print str(e)
count +=1
if count > Settings.MAX_RETRY_COUNT:
sys.exit(-1)
time.sleep(Settings.RETRY_INTERVAL)
worker_count = q.qsize()
wait_circle = worker_count/Settings.MAX_CONCURRENT_NUM
while True:
if q.empty()==True:
break
msg_list = []
for i in xrange(Settings.MAX_CONCURRENT_NUM):
if not q.empty():
msg = q.get()
msg_list.append(msg)
for item in msg_list:
try:
DoScanTask.delay(item)
except:
pass
time.sleep(wait_circle*Settings.SCAN_TASK_INTERVAL)
time.sleep(Settings.DISPATCH_TASK_INTERVAL)