-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler.py
67 lines (57 loc) · 1.5 KB
/
scheduler.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 -*-
# Author: ShiWenWen
from multiprocessing import Process
from api import app
from getter import Getter
from tester import Tester
import time
# 测试周期
TESTER_CYCLE = 20
# 获取周期
GETTER_CYCLE = 20
# 是否允许测试服务
TESTER_ENABLED = True
# 是否允许获取服务
GETTER_ENABLED = True
# 是否启动api服务
API_ENABLED = True
class Scheduler:
def schedule_tester(self, cycle=TESTER_CYCLE):
"""
定时测试代理
:param cycle: 定时时间
"""
tester = Tester()
while True:
print('测试器运行')
tester.run()
time.sleep(cycle)
def schedule_getter(self, cycle=GETTER_CYCLE):
"""
定时获取代理
:param cycle:
"""
getter = Getter()
while True:
print('开始定时获取代理')
getter.run()
time.sleep(cycle)
def schedule_api(self):
"""
开启api
:return:
"""
app.run()
def run(self):
print('代理池调度器开始运行')
if GETTER_ENABLED:
getter_process = Process(target=self.schedule_getter)
getter_process.start()
if TESTER_ENABLED:
tester_process = Process(target=self.schedule_tester)
tester_process.start()
if API_ENABLED:
api_process = Process(target=self.schedule_api)
api_process.run()
if __name__ == '__main__':
Scheduler().run()