余尚辉 4 meses atrás
pai
commit
39ac75da36
2 arquivos alterados com 15 adições e 6 exclusões
  1. 13 5
      src/core/callcenter/agent.py
  2. 2 1
      src/core/datasource.py

+ 13 - 5
src/core/callcenter/agent.py

@@ -14,6 +14,8 @@ from src.core.callcenter.api import AgentActionRequest, AgentInfo, AgentQueryReq
 from src.core.callcenter.push import PushHandler
 from src.core.datasource import RedisHandler
 
+from concurrent.futures import ThreadPoolExecutor
+import threading
 
 class AgentOperService:
 
@@ -469,12 +471,14 @@ class AgentActionLogService:
 
 
 class AgentStateService:
-    state_service_id_data_map = defaultdict(lambda: defaultdict(int))  # 作为静态变量
+
     def __init__(self, client, logger):
         self.inbound_client = client
         self.logger = logger
         self.redis_handler = RedisHandler()
         self.assigned_recycle_millisecond = 60000
+        self.state_service_id_data_map = defaultdict(dict)
+        self.executor = ThreadPoolExecutor(max_workers=10)
     
     def idle(self, saas_id, agent_id, phone_num):
         human_service = _get_human_service_service(saas_id, agent_id)
@@ -551,7 +555,7 @@ class AgentStateService:
 
     def get_cache_agent_list(self, saas_id, service_id):
         redis_key = self._key(saas_id, service_id)
-        map_cache_by_key = self.redis_handler.redis.get(redis_key, str)
+        map_cache_by_key = self.redis_handler.redis.hgetall(redis_key)
 
         if not map_cache_by_key:  # 检查字典是否为空
             return []  # 返回空列表
@@ -595,13 +599,17 @@ class AgentStateService:
     def update_report_state(self, saas_id, service_id):
         key = self._key(saas_id, service_id)
         # data_map 这个地方有疑问
-        data_map = self.state_service_id_data_map.setdefault(key, {})
+        data_map = self.state_service_id_data_map[key]
         idle = HumanState.IDLE
         if idle.value not in data_map:
-            data_map[idle.code] = self.do_report_real_time_human_service_id(saas_id, service_id, idle)
+            data_map[idle.code] = threading.Lock()
+            self.executor.submit(self.do_report_real_time_human_service_id, saas_id, service_id, idle)
+            # data_map[idle.code] = self.do_report_real_time_human_service_id(saas_id, service_id, idle)
         busy = HumanState.BUSY
         if busy.value not in data_map:
-            data_map[busy.code] = self.do_report_real_time_human_service_id(saas_id, service_id, busy)
+            data_map[busy.code] = threading.Lock()
+            self.executor.submit(self.do_report_real_time_human_service_id, saas_id, service_id, busy)
+            # data_map[busy.code] = self.do_report_real_time_human_service_id(saas_id, service_id, busy)
 
     def do_report_real_time_human_service_id(self, saas_id, service_id, human_state):
         name = "cti_center_real_time_human_service_state"

+ 2 - 1
src/core/datasource.py

@@ -194,7 +194,8 @@ class RedisHandler:
         try:
             print(f"redis_host:{host}")
             self.redis = StrictRedis(
-                connection_pool=ConnectionPool(host=host, port=port, db=db, password=password))
+                connection_pool=ConnectionPool(host=host, port=port, db=db, password=password),
+                decode_responses=True)
         except Exception as e:
             traceback.print_exc()