-
Notifications
You must be signed in to change notification settings - Fork 5
/
rpc_server.py
27 lines (25 loc) · 992 Bytes
/
rpc_server.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
import zerorpc
from apscheduler.events import EVENT_JOB_MISSED,EVENT_JOB_ERROR, EVENT_JOB_EXECUTED
from scheduler.schedulers.gevent import ExtendGeventcheduler
from job.listener import CronJobListener
from app.common.logger import logger
from app.config import settings
from rpc import SchedulerService
config = settings.SCHEDULER_CONFIG
scheduler = ExtendGeventcheduler(
jobstores=config.stores,
executors=config.executors,
job_defaults=config.default
)
listener = CronJobListener(schedule=scheduler).job_listener
scheduler.add_listener(listener,EVENT_JOB_EXECUTED|EVENT_JOB_ERROR|EVENT_JOB_MISSED)
scheduler.start()
try:
logger.info('schduler has been started')
server = zerorpc.Server(SchedulerService(scheduler=scheduler),pool_size=settings.RPC_POOL_SIZE, heartbeat=60)
server.bind(settings.RPC_URL)
logger.info('RPC server is run at %s' %settings.RPC_URL)
server.run()
except KeyboardInterrupt:
server.stop()
logger.warning('stop RPC Server')