监听调度系统定时执行任务python_websock

由于调度系统的定时任务通过ws://10.200.9.183:2017/(ws:webservce服务0可以从浏览器的console控制台获取到。
向webservice发送'first:koala',即可查询到定时任务。


import asyncio
import logging
from datetime import datetime
from aiowebsocket.converses import AioWebSocket

async def startup(uri):
async with AioWebSocket(uri) as aws:
converse = aws.manipulator
# message = b'AioWebSocket - Async WebSocket Client'
#将message值设置为first:koala,即前端用来调用调度系统定时任务的语句。
message=b'first:koala'
while True:
#向websock发送定时任务的消息
await converse.send(message)
print('{time}-Client send: {message}'
.format(time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), message=message))
#接收到websock定时任务的任务名称
mes = await converse.receive()
print('{time}-Client receive: {rec}'
.format(time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), rec=mes))

if name == 'main':
#调度系统定时任务的websock地址
remote = 'ws://10.200.9.183:2017/'

try:
    asyncio.get_event_loop().run_until_complete(startup(remote))

except KeyboardInterrupt as exc:
    logging.info('Quit.')`

由于定时任务执行需要时间,故需要等待至少3分钟后查看websocket返回结果

posted @ 2020-07-16 20:19  hisweetyGirl  阅读(510)  评论(0编辑  收藏  举报