|
@@ -9,16 +9,18 @@ import sys
|
|
import ESL
|
|
import ESL
|
|
import time
|
|
import time
|
|
import mmh3
|
|
import mmh3
|
|
|
|
+import uuid
|
|
import threading
|
|
import threading
|
|
import traceback
|
|
import traceback
|
|
import concurrent.futures
|
|
import concurrent.futures
|
|
|
|
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
|
|
|
|
|
+from src.core.callcenter import BizException
|
|
from src.core.callcenter.cache import Cache
|
|
from src.core.callcenter.cache import Cache
|
|
from src.core.callcenter.api import MakeCallContext, DelayAction, CallInfo, DeviceInfo, NextCommand
|
|
from src.core.callcenter.api import MakeCallContext, DelayAction, CallInfo, DeviceInfo, NextCommand
|
|
from src.core.callcenter.callback import Callback
|
|
from src.core.callcenter.callback import Callback
|
|
-from src.core.callcenter.constant import SK, EMPTY, CTI_ENGINE_DELAY_ACTION_LOCK, HOLD_MUSIC_PATH, saasId
|
|
|
|
|
|
+from src.core.callcenter.constant import SK, EMPTY, CTI_ENGINE_DELAY_ACTION_LOCK, HOLD_MUSIC_PATH, WaitingHangupMusicPath, saasId
|
|
from src.core.callcenter.esl.constant.esl_constant import BRIDGE_VARIABLES, BRIDGE, HANGUP, NORMAL_CLEARING, SIP_HEADER, \
|
|
from src.core.callcenter.esl.constant.esl_constant import BRIDGE_VARIABLES, BRIDGE, HANGUP, NORMAL_CLEARING, SIP_HEADER, \
|
|
SPACE, SPLIT, SOFIA, \
|
|
SPACE, SPLIT, SOFIA, \
|
|
ORIGINATE, PARK, SET, EAVESDROP, SMF_ALEG, EXECUTE, PLAYBACK, PAUSE, TRANSFER, UUID_TRANSFER, UUID_BROADCAST, \
|
|
ORIGINATE, PARK, SET, EAVESDROP, SMF_ALEG, EXECUTE, PLAYBACK, PAUSE, TRANSFER, UUID_TRANSFER, UUID_BROADCAST, \
|
|
@@ -28,7 +30,7 @@ import src.core.callcenter.esl.utils.esl_event_util as EslEventUtil
|
|
import src.core.callcenter.esl.handler as event_handler
|
|
import src.core.callcenter.esl.handler as event_handler
|
|
from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic, profile1, profile2, sipHeaderCallId
|
|
from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic, profile1, profile2, sipHeaderCallId
|
|
from src.core.callcenter.enumeration import CallCause, DeviceType, DelayActionEnum, HangupDir, CallType, NextType, \
|
|
from src.core.callcenter.enumeration import CallCause, DeviceType, DelayActionEnum, HangupDir, CallType, NextType, \
|
|
- Direction, CdrType
|
|
|
|
|
|
+ Direction, CdrType, BizErrorCode
|
|
from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEslEventHandler
|
|
from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEslEventHandler
|
|
from src.core.callcenter.snowflake import Snowflake
|
|
from src.core.callcenter.snowflake import Snowflake
|
|
from src.core.datasource import SERVE_HOST
|
|
from src.core.datasource import SERVE_HOST
|
|
@@ -166,14 +168,15 @@ class InboundClient:
|
|
if device_info.device_type <= DeviceType.ROBOT.code:
|
|
if device_info.device_type <= DeviceType.ROBOT.code:
|
|
call_info.hangup_dir = HangupDir.PLATFORM_HANGUP.code
|
|
call_info.hangup_dir = HangupDir.PLATFORM_HANGUP.code
|
|
call_info.hangup_code = CallCause.CALL_TIMEOUT.code
|
|
call_info.hangup_code = CallCause.CALL_TIMEOUT.code
|
|
- # if device_info.device_type.code == DeviceType.CUSTOMER.code:
|
|
|
|
- # call_info.user_no_answer_end_call = True
|
|
|
|
-
|
|
|
|
- if not device_info.end_time and device_info.device_type.code == DeviceType.CUSTOMER.code:
|
|
|
|
- channel = self.show_channel(device_id)
|
|
|
|
- if channel:
|
|
|
|
- delay_action = DelayAction(call_id=call_id, device_id=device_id)
|
|
|
|
- self.cache.add_delay_message(DelayActionEnum.CALL_TIMEOUT_DECR, delay_action, timeouts=20)
|
|
|
|
|
|
+
|
|
|
|
+ if device_info.device_type.code == DeviceType.CUSTOMER.code:
|
|
|
|
+ call_info.user_no_answer_end_call = True
|
|
|
|
+
|
|
|
|
+ # if not device_info.end_time and device_info.device_type.code == DeviceType.CUSTOMER.code:
|
|
|
|
+ # channel = self.show_channel(device_id)
|
|
|
|
+ # if channel:
|
|
|
|
+ # delay_action = DelayAction(call_id=call_id, device_id=device_id)
|
|
|
|
+ # self.cache.add_delay_message(DelayActionEnum.CALL_TIMEOUT_DECR, delay_action, timeouts=20)
|
|
self.cache.add_call_info(call_info)
|
|
self.cache.add_call_info(call_info)
|
|
self.hangup_call(call_id, device_id, CallCause.CALL_TIMEOUT)
|
|
self.hangup_call(call_id, device_id, CallCause.CALL_TIMEOUT)
|
|
self.dataHandleServer.update_record(call_id, {"status": 0})
|
|
self.dataHandleServer.update_record(call_id, {"status": 0})
|
|
@@ -181,7 +184,7 @@ class InboundClient:
|
|
call_info = self.cache.get_call_info(call_id)
|
|
call_info = self.cache.get_call_info(call_id)
|
|
if not call_info or not call_info.next_commands:
|
|
if not call_info or not call_info.next_commands:
|
|
return
|
|
return
|
|
- self.logger.debug("播放结束音乐失败,进行挂机 callId:%s", call_id)
|
|
|
|
|
|
+ self.logger.info("播放结束音乐失败,进行挂机 callId:%s", call_id)
|
|
next_types = [x.next_type for x in call_info.next_commands]
|
|
next_types = [x.next_type for x in call_info.next_commands]
|
|
if NextType.NEXT_HANGUP.code in next_types:
|
|
if NextType.NEXT_HANGUP.code in next_types:
|
|
for device_id in call_info.device_list:
|
|
for device_id in call_info.device_list:
|
|
@@ -195,12 +198,17 @@ class InboundClient:
|
|
device_list = [v for k,v in call_info.device_info_map.items() if v.device_type == DeviceType.CUSTOMER]
|
|
device_list = [v for k,v in call_info.device_info_map.items() if v.device_type == DeviceType.CUSTOMER]
|
|
if device_list and len(device_list) == 1:
|
|
if device_list and len(device_list) == 1:
|
|
device_id = device_list[0].device_id
|
|
device_id = device_list[0].device_id
|
|
- self.bridge_break(call_id, device_id)
|
|
|
|
- self.hold_play(device_id, HOLD_MUSIC_PATH)
|
|
|
|
|
|
+ self.break0(device_id)
|
|
|
|
+ if not WaitingHangupMusicPath:
|
|
|
|
+ self.hangup_call(call_id, device_id, CallCause.WAITING_TIMEOUT)
|
|
|
|
+ return
|
|
|
|
+ self.hold_play(device_id, WaitingHangupMusicPath)
|
|
self.play_timeout(call_id, timeout=30)
|
|
self.play_timeout(call_id, timeout=30)
|
|
|
|
+ next_command = NextCommand(device_id = device_id, next_type=NextType.NEXT_HANGUP.code)
|
|
|
|
+ call_info.next_commands = [next_command]
|
|
self.cache.add_call_info(call_info)
|
|
self.cache.add_call_info(call_info)
|
|
self.logger.info("waitingTimeOut 开始播放结束音乐 callId:%s customerDeviceId:%s playFile:%s", call_id,
|
|
self.logger.info("waitingTimeOut 开始播放结束音乐 callId:%s customerDeviceId:%s playFile:%s", call_id,
|
|
- device_id, HOLD_MUSIC_PATH)
|
|
|
|
|
|
+ device_id, WaitingHangupMusicPath)
|
|
|
|
|
|
def make_call_new(self, context: MakeCallContext):
|
|
def make_call_new(self, context: MakeCallContext):
|
|
# self.logger.info("拨打测试context:%s", context.__dict__)
|
|
# self.logger.info("拨打测试context:%s", context.__dict__)
|
|
@@ -210,7 +218,7 @@ class InboundClient:
|
|
builder = [
|
|
builder = [
|
|
'{', context.get_sip_header(), '}'
|
|
'{', context.get_sip_header(), '}'
|
|
]
|
|
]
|
|
-
|
|
|
|
|
|
+ self.call_timeout(context.call_id, context.device_id, context.timeout)
|
|
if context.device_type == DeviceType.CUSTOMER.code:
|
|
if context.device_type == DeviceType.CUSTOMER.code:
|
|
profile = self.expression(profile1, params)
|
|
profile = self.expression(profile1, params)
|
|
builder.append(f"{SOFIA}{SK}{profile}{SK}{called}{PARK}")
|
|
builder.append(f"{SOFIA}{SK}{profile}{SK}{called}{PARK}")
|
|
@@ -304,9 +312,9 @@ class InboundClient:
|
|
builder.append("all")
|
|
builder.append("all")
|
|
command = ' '.join(builder)
|
|
command = ' '.join(builder)
|
|
if sync:
|
|
if sync:
|
|
- self.con.api(command, EMPTY)
|
|
|
|
|
|
+ self.api(command, desc="break0")
|
|
else:
|
|
else:
|
|
- self.con.bgapi(command, EMPTY)
|
|
|
|
|
|
+ self.bgapi(command, desc="break0")
|
|
|
|
|
|
def hold(self, smf, uuid, display):
|
|
def hold(self, smf, uuid, display):
|
|
builder = [
|
|
builder = [
|
|
@@ -487,40 +495,10 @@ class OutboundClient:
|
|
def __init__(self, agent, app):
|
|
def __init__(self, agent, app):
|
|
self.app = app
|
|
self.app = app
|
|
self.logger = app.logger
|
|
self.logger = app.logger
|
|
- self.whitelist = []
|
|
|
|
- self.update_whitelist() # 初始化加载白名单
|
|
|
|
-
|
|
|
|
- # 定时更新白名单
|
|
|
|
- threading.Thread(target=self.refresh_whitelist, daemon=True).start()
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- self.dataHandleServer = DataHandleServer(app)
|
|
|
|
- #threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent, logger)).start()
|
|
|
|
server_thread = threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent))
|
|
server_thread = threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent))
|
|
server_thread.daemon = True # 设置守护线程
|
|
server_thread.daemon = True # 设置守护线程
|
|
server_thread.start()
|
|
server_thread.start()
|
|
|
|
|
|
- def update_whitelist(self):
|
|
|
|
- with self.app.app_context():
|
|
|
|
- phones = Whitelist.query.filter_by(del_flag=0).all()
|
|
|
|
- self.whitelist = [phone.phone for phone in phones]
|
|
|
|
- self.logger.info("Whitelist updated: %s", self.whitelist)
|
|
|
|
-
|
|
|
|
- def refresh_whitelist(self):
|
|
|
|
- while True:
|
|
|
|
- time.sleep(3600) # 每 1小时 更新一次
|
|
|
|
- self.update_whitelist()
|
|
|
|
-
|
|
|
|
- def load_whitelist(self):
|
|
|
|
- return self.whitelist
|
|
|
|
-
|
|
|
|
- def load_agent_monitor(self):
|
|
|
|
- with self.app.app_context():
|
|
|
|
- agents = AgentMonitor.query.filter_by(check_state=0,service_state=2).all()
|
|
|
|
- agent_nums = [agent.agent_num for agent in agents]
|
|
|
|
- return agent_nums
|
|
|
|
-
|
|
|
|
-
|
|
|
|
class ESLRequestHandler(socketserver.BaseRequestHandler):
|
|
class ESLRequestHandler(socketserver.BaseRequestHandler):
|
|
def setup(self):
|
|
def setup(self):
|
|
try:
|
|
try:
|
|
@@ -536,7 +514,6 @@ class OutboundClient:
|
|
self.server.logger.info('Event-Name: %s', event_name)
|
|
self.server.logger.info('Event-Name: %s', event_name)
|
|
device_id = info.getHeader("unique-id")
|
|
device_id = info.getHeader("unique-id")
|
|
caller_number = info.getHeader("Caller-Caller-ID-Number") # 获取来电号码
|
|
caller_number = info.getHeader("Caller-Caller-ID-Number") # 获取来电号码
|
|
- whitelist = self.server.load_whitelist()
|
|
|
|
|
|
|
|
call_id = 'C' + str(Snowflake().next_id())
|
|
call_id = 'C' + str(Snowflake().next_id())
|
|
new_device_id = 'D' + str(Snowflake().next_id())
|
|
new_device_id = 'D' + str(Snowflake().next_id())
|
|
@@ -544,33 +521,51 @@ class OutboundClient:
|
|
kwargs = json.loads(info.serialize('json'))
|
|
kwargs = json.loads(info.serialize('json'))
|
|
kwargs['variable_sip_h_P-LIBRA-CallId'] = call_id
|
|
kwargs['variable_sip_h_P-LIBRA-CallId'] = call_id
|
|
kwargs['variable_sip_h_P-LIBRA-DeviceId'] = new_device_id
|
|
kwargs['variable_sip_h_P-LIBRA-DeviceId'] = new_device_id
|
|
- call_info = {
|
|
|
|
- "session_id": call_id,
|
|
|
|
- "time_begin": datetime.utcnow(),
|
|
|
|
- "category": 0,
|
|
|
|
- "phone": caller_number
|
|
|
|
- }
|
|
|
|
- # 检查白名单
|
|
|
|
- if caller_number in whitelist:
|
|
|
|
- agents = self.server.load_agent_monitor()
|
|
|
|
- destination = random.choice(agents) # 随机取一个坐席号
|
|
|
|
- # 直接转接到人工坐席
|
|
|
|
- self.server.logger.info( "Caller %s is in whitelist, agents: %s, destination: %s"% (caller_number, agents, destination))
|
|
|
|
- call_info['type']= 0
|
|
|
|
- call_info['agent_num'] = destination
|
|
|
|
- else:
|
|
|
|
|
|
+
|
|
|
|
+ bucket = self.server.get_bucket(call_id)
|
|
|
|
+ whitelist = self.server.get_whitelist()
|
|
|
|
+ if bucket and bucket.name == 'AI':
|
|
#转到ai机器人
|
|
#转到ai机器人
|
|
destination = self.server.agent.register(**kwargs)
|
|
destination = self.server.agent.register(**kwargs)
|
|
- self.server.logger.info("device_id=%s, destination=%s, new_device_id=%s"% (device_id, destination, new_device_id))
|
|
|
|
- call_info['type'] = 1
|
|
|
|
- call_info['service_category'] = 1
|
|
|
|
- call_info['user_id'] = destination
|
|
|
|
- call_info['user_name'] = f"机器人{destination}"
|
|
|
|
|
|
+ self.server.logger.info("device_id=%s, destination=%s, new_device_id=%s" % (device_id, destination, new_device_id))
|
|
self.build_call_info(call_id, device_id, new_device_id, str(destination), **kwargs)
|
|
self.build_call_info(call_id, device_id, new_device_id, str(destination), **kwargs)
|
|
self.server.cache.add_device_user_part(device_id, destination)
|
|
self.server.cache.add_device_user_part(device_id, destination)
|
|
- con.execute("bridge", "{sip_h_P-LIBRA-CallId=%s,sip_h_P-LIBRA-DeviceId=%s,origination_uuid=%s}user/%s"%(call_id, new_device_id, new_device_id, destination), device_id)
|
|
|
|
|
|
+ con.execute("bridge", "{sip_h_P-LIBRA-CallId=%s,sip_h_P-LIBRA-DeviceId=%s,origination_uuid=%s}user/%s" % (call_id, new_device_id, new_device_id, destination), device_id)
|
|
|
|
+ self.server.dataHandleServer.create_record(call_id, caller_number, 1, service_category=1, destination=destination)
|
|
|
|
+ elif caller_number in whitelist:
|
|
|
|
+ # 检查白名单
|
|
|
|
+ self.build_call_info(call_id, device_id, new_device_id, destination=None, **kwargs)
|
|
|
|
+ self.server.agent.acd_service.transfer_to_agent(call_id, new_device_id)
|
|
|
|
+ self.server.dataHandleServer.create_record(call_id, caller_number, 0, service_category=None, destination=None)
|
|
|
|
+ else:
|
|
|
|
+ # 传统服务
|
|
|
|
+ self.build_call_info(call_id, device_id, new_device_id, destination=None, **kwargs)
|
|
|
|
+ self.server.agent.acd_service.transfer_to_agent(call_id, new_device_id)
|
|
|
|
+ self.server.dataHandleServer.create_record(call_id, caller_number, 2, service_category=None, destination=None)
|
|
|
|
+
|
|
|
|
+ # # 检查白名单
|
|
|
|
+ # if caller_number in whitelist:
|
|
|
|
+ # agents = self.server.load_agent_monitor()
|
|
|
|
+ # destination = random.choice(agents) # 随机取一个坐席号
|
|
|
|
+ # # 直接转接到人工坐席
|
|
|
|
+ # self.server.logger.info( "Caller %s is in whitelist, agents: %s, destination: %s"% (caller_number, agents, destination))
|
|
|
|
+ # call_info['type']= 0
|
|
|
|
+ # call_info['agent_num'] = destination
|
|
|
|
+ # else:
|
|
|
|
+ # #转到ai机器人
|
|
|
|
+ # destination = self.server.agent.register(**kwargs)
|
|
|
|
+ # self.server.logger.info("device_id=%s, destination=%s, new_device_id=%s"% (device_id, destination, new_device_id))
|
|
|
|
+ # call_info['type'] = 1
|
|
|
|
+ # call_info['service_category'] = 1
|
|
|
|
+ # call_info['user_id'] = destination
|
|
|
|
+ # call_info['user_name'] = f"机器人{destination}"
|
|
|
|
+ # self.build_call_info(call_id, device_id, new_device_id, str(destination), **kwargs)
|
|
|
|
+ # self.server.cache.add_device_user_part(device_id, destination)
|
|
|
|
+ # con.execute("bridge", "{sip_h_P-LIBRA-CallId=%s,sip_h_P-LIBRA-DeviceId=%s,origination_uuid=%s}user/%s"%(call_id, new_device_id, new_device_id, destination), device_id)
|
|
|
|
+
|
|
|
|
+ # self.server.dataHandleServer.create_record(call_info)
|
|
|
|
+
|
|
|
|
|
|
- self.server.dataHandleServer.create_record(call_info)
|
|
|
|
# destination = "user/1001"
|
|
# destination = "user/1001"
|
|
# msg = ESL.ESLevent("sendmsg", uuid)
|
|
# msg = ESL.ESLevent("sendmsg", uuid)
|
|
# msg.addHeader("call-command", "execute")
|
|
# msg.addHeader("call-command", "execute")
|
|
@@ -613,28 +608,79 @@ class OutboundClient:
|
|
cti_flow_id=None, conference=None, agent_name=None, from_agent=None, caller=None, called=None, display=None, called_location=None, caller_location=None, ring_start_time=None, ring_end_time=None, answer_time=None, bridge_time=None, end_time=None, talk_time=None, sip_protocol=None, channel_name=None, hangup_cause=None, ring_cause=None, sip_status=None, record=None, record_time=None, record_start_time=None, state=None, apparent_number=None, caller_display=None)
|
|
cti_flow_id=None, conference=None, agent_name=None, from_agent=None, caller=None, called=None, display=None, called_location=None, caller_location=None, ring_start_time=None, ring_end_time=None, answer_time=None, bridge_time=None, end_time=None, talk_time=None, sip_protocol=None, channel_name=None, hangup_cause=None, ring_cause=None, sip_status=None, record=None, record_time=None, record_start_time=None, state=None, apparent_number=None, caller_display=None)
|
|
|
|
|
|
call_info.device_list.append(device_id)
|
|
call_info.device_list.append(device_id)
|
|
- self.server.logger.info("liuwei::debugger:3333::call_id=%s, device_id=%s" % (call_id, device_id))
|
|
|
|
|
|
+ # self.server.logger.info("liuwei::debugger:3333::call_id=%s, device_id=%s" % (call_id, device_id))
|
|
call_info.device_list.append(new_device_id)
|
|
call_info.device_list.append(new_device_id)
|
|
- self.server.logger.info("liuwei::debugger:4444::call_id=%s, device_id=%s" % (call_id, new_device_id))
|
|
|
|
|
|
+ # self.server.logger.info("liuwei::debugger:4444::call_id=%s, device_id=%s" % (call_id, new_device_id))
|
|
# call_info.next_commands.append(NextCommand(device_id, NextType.NEXT_CALL_BRIDGE.code, new_device_id))
|
|
# call_info.next_commands.append(NextCommand(device_id, NextType.NEXT_CALL_BRIDGE.code, new_device_id))
|
|
call_info.device_info_map = {device_id: device_custom, new_device_id: device_bot}
|
|
call_info.device_info_map = {device_id: device_custom, new_device_id: device_bot}
|
|
- self.server.logger.info("lwoutBound, call_info=%s"%(call_info))
|
|
|
|
|
|
+ # self.server.logger.info("lwoutBound, call_info=%s"%(call_info))
|
|
self.server.cache.add_call_info(call_info)
|
|
self.server.cache.add_call_info(call_info)
|
|
|
|
|
|
|
|
|
|
class CustomTCPServer(socketserver.TCPServer):
|
|
class CustomTCPServer(socketserver.TCPServer):
|
|
- def __init__(self, server_address, RequestHandlerClass, agent, app,whitelist_loader,load_agent_monitor,dataHandleServer):
|
|
|
|
|
|
+ def __init__(self, server_address, RequestHandlerClass, agent, app):
|
|
|
|
+ super().__init__(server_address, RequestHandlerClass)
|
|
self.agent = agent
|
|
self.agent = agent
|
|
|
|
+ self.app = app
|
|
self.cache = Cache(app)
|
|
self.cache = Cache(app)
|
|
self.logger = app.logger
|
|
self.logger = app.logger
|
|
- self.load_whitelist = whitelist_loader
|
|
|
|
- self.load_agent_monitor = load_agent_monitor
|
|
|
|
- self.dataHandleServer = dataHandleServer
|
|
|
|
- super().__init__(server_address, RequestHandlerClass)
|
|
|
|
|
|
+ self.whitelist = []
|
|
|
|
+ self.buckets = []
|
|
|
|
+ self.update_whitelist() # 初始化加载白名单
|
|
|
|
+ self.update_bucket() #初始化分流
|
|
|
|
+ self.dataHandleServer = DataHandleServer(app)
|
|
|
|
+ # 定时更新白名单
|
|
|
|
+ threading.Thread(target=self.refresh_whitelist, daemon=True).start()
|
|
|
|
+ threading.Thread(target=self.refresh_bucket, daemon=True).start()
|
|
|
|
+
|
|
|
|
+ def update_whitelist(self):
|
|
|
|
+ with self.app.app_context():
|
|
|
|
+ phones = Whitelist.query.filter_by(del_flag=0).all()
|
|
|
|
+ self.whitelist = [phone.phone for phone in phones]
|
|
|
|
+ self.logger.info("Whitelist updated: %s", self.whitelist)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def refresh_whitelist(self):
|
|
|
|
+ while True:
|
|
|
|
+ time.sleep(3600) # 每 1小时 更新一次
|
|
|
|
+ self.update_whitelist()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def get_whitelist(self):
|
|
|
|
+ return self.whitelist
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def load_agent_monitor(self):
|
|
|
|
+ with self.app.app_context():
|
|
|
|
+ agents = AgentMonitor.query.filter_by(check_state=0, service_state=2).all()
|
|
|
|
+ agent_nums = [agent.agent_num for agent in agents]
|
|
|
|
+ return agent_nums
|
|
|
|
+
|
|
|
|
+ def get_bucket(self, custom_uuid=None):
|
|
|
|
+ custom_uuid == custom_uuid if custom_uuid else str(uuid.uuid4())
|
|
|
|
+ random_id = abs(mmh3.hash(custom_uuid))
|
|
|
|
+ if len(self.buckets) <= 0:
|
|
|
|
+ raise BizException(BizErrorCode.RECORD_NOT_EXIST_ERROR)
|
|
|
|
+ for bucket in self.buckets:
|
|
|
|
+ num = (random_id % 100 + 100) %100
|
|
|
|
+ if num >= bucket.lower and num < bucket.upper:
|
|
|
|
+ return bucket
|
|
|
|
+ return self.buckets[0]
|
|
|
|
+
|
|
|
|
+ def update_bucket(self):
|
|
|
|
+ with self.app.app_context():
|
|
|
|
+ buckets = Bucket.query.filter_by(eid='001').all()
|
|
|
|
+ self.buckets = buckets
|
|
|
|
+ self.logger.info("bucket updated: %s", self.whitelist)
|
|
|
|
+
|
|
|
|
+ def refresh_bucket(self):
|
|
|
|
+ while True:
|
|
|
|
+ time.sleep(60) # 每 1分钟 更新一次
|
|
|
|
+ self.update_bucket()
|
|
|
|
|
|
def start(self, HOST='0.0.0.0', PORT=8084, agent=None):
|
|
def start(self, HOST='0.0.0.0', PORT=8084, agent=None):
|
|
# HOST, PORT = "0.0.0.0", 8084
|
|
# HOST, PORT = "0.0.0.0", 8084
|
|
# 创建一个 TCP 服务器
|
|
# 创建一个 TCP 服务器
|
|
- with self.CustomTCPServer((HOST, PORT), self.ESLRequestHandler, agent, self.app, self.load_whitelist, self.load_agent_monitor,self.dataHandleServer) as server:
|
|
|
|
|
|
+ with self.CustomTCPServer((HOST, PORT), self.ESLRequestHandler, agent, self.app) as server:
|
|
print(f"ESL server listening on {HOST}:{PORT}")
|
|
print(f"ESL server listening on {HOST}:{PORT}")
|
|
server.serve_forever()
|
|
server.serve_forever()
|