feat: get_tyy_data单独处理
This commit is contained in:
parent
2f8beec37f
commit
beddfe98ba
|
|
@ -9,7 +9,6 @@ import uuid
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import requests
|
import requests
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
|
|
||||||
myLogger = logging.getLogger('log')
|
myLogger = logging.getLogger('log')
|
||||||
|
|
||||||
|
|
@ -296,34 +295,9 @@ def get_svs_char(host, port, flow_unit=0, timeout=10):
|
||||||
raise ParseError("SVS未返回有效数据")
|
raise ParseError("SVS未返回有效数据")
|
||||||
|
|
||||||
|
|
||||||
def get_tyy_data(host, port, svs_host=None, svs_port=None, svs_flow=0):
|
def get_tyy_data(*args):
|
||||||
"""获取采集器数据;若传入 svs_host/svs_port,并行获取 SVS 识别字符并合并返回。
|
host, port = args[0], int(args[1])
|
||||||
|
|
||||||
采集器与 SVS 任一失败均整体抛错。
|
|
||||||
"""
|
|
||||||
port = int(port)
|
|
||||||
|
|
||||||
def fetch_tyy():
|
|
||||||
r = requests.get(f"http://127.0.0.1:2300?host={host}&port={port}")
|
r = requests.get(f"http://127.0.0.1:2300?host={host}&port={port}")
|
||||||
res = r.json()
|
res = r.json()
|
||||||
if "err_msg" in res:
|
if "err_msg" in res:
|
||||||
raise ParseError(res["err_msg"])
|
raise ParseError(res["err_msg"])
|
||||||
return res
|
|
||||||
|
|
||||||
if not (svs_host and svs_port):
|
|
||||||
return fetch_tyy()
|
|
||||||
|
|
||||||
# 采集器与 SVS 并行触发,尽量贴近同一时刻;任一失败在 result() 处抛出
|
|
||||||
with ThreadPoolExecutor(max_workers=2) as ex:
|
|
||||||
tyy_future = ex.submit(fetch_tyy)
|
|
||||||
svs_future = ex.submit(get_svs_char, svs_host, svs_port, svs_flow)
|
|
||||||
res = tyy_future.result()
|
|
||||||
svs = svs_future.result()
|
|
||||||
|
|
||||||
if not isinstance(res, dict):
|
|
||||||
# 采集器返回的不是 dict 时,包成一个完整 dict
|
|
||||||
res = {"tyy": res}
|
|
||||||
res["svs_char"] = svs["char"]
|
|
||||||
res["svs_fields"] = svs["fields"]
|
|
||||||
res["svs_raw"] = svs["raw"]
|
|
||||||
return res
|
|
||||||
Loading…
Reference in New Issue