-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.py
49 lines (38 loc) · 1.31 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
import time
from Crawler.Getter import Getter
from Dbs.redis_client import OrderSetClient
from Server.core import app
from Tester.Tester import Tester
from log.logs import Logger
from configs import GETTER_CYCLE,TESTER_CYCLE,TESTER_ENABLED, API_ENABLED, GETTER_ENABLED
from multiprocessing import Process
class Scheduler(object):
logger = Logger()
def scheduler_tester(self, cycle=TESTER_CYCLE):
tester = Tester()
while True:
self.logger.info('Tester is running...')
tester.run()
time.sleep(TESTER_CYCLE)
def scheduler_getter(self, cycle=GETTER_CYCLE):
getter = Getter()
while True:
self.logger.info('Getter is running...')
getter.run()
time.sleep(GETTER_CYCLE)
def schedule_api(self):
'''
开启api
'''
app()
def run(self):
self.logger.info('代理池开始运行')
if TESTER_ENABLED:
tester_process = Process(target=self.scheduler_tester)
tester_process.start()
if GETTER_ENABLED:
getter_process = Process(target=self.scheduler_getter)
getter_process.start()
if API_ENABLED:
api_process = Process(target=self.schedule_api)
api_process.start()