DavidLiu 3 ay önce
ebeveyn
işleme
d99e2aef30
2 değiştirilmiş dosya ile 30 ekleme ve 1 silme
  1. 5 0
      src/core/callcenter/cache.py
  2. 25 1
      src/core/voip/bot.py

+ 5 - 0
src/core/callcenter/cache.py

@@ -227,6 +227,11 @@ class Cache:
         # self.logger.info("get_pjsua_thread_lock %s", _lock)
         return _lock
 
+    def del_pjsua_thread_lock(self):
+        minute = datetime.now().strftime('%Y%m%d%H%M')
+        key = BOT_PJSUA_THREAD_LOCK % minute
+        return self.redis_handler.redis.delete(key)
+
     def set_pjsua_thread_lock(self, expire=60*3):
         minute = datetime.now().strftime('%Y%m%d%H%M')
         key = BOT_PJSUA_THREAD_LOCK % minute

+ 25 - 1
src/core/voip/bot.py

@@ -322,7 +322,8 @@ class MyCall(pj.Call):
             if not os.path.isfile(f):
                 self.logger.info(f"Sending bot speaker, not exists, player_file: {player_file}, player_id: {player_id}, isActive: {self.isActive()}")
                 return
-
+        key = murmur3_32(str(datetime.now().timestamp()))
+        self.agent.call_players[key] = [datetime.now().timestamp()]
         # print('self.player_complete_dict[player_id]D:', player_id, player_file, self.player_complete_dict[player_id])
         self.logger.info(f"Sending bot speaker, 111, player_file: {player_file}, player_id: {player_id}, isActive: {self.isActive()}")
         self.audio_player = MyAudioMediaPlayer(player_id, self.audio_media, on_complete=self.on_media_player_complete)
@@ -334,6 +335,7 @@ class MyCall(pj.Call):
             self.audio_player.createPlaylist(player_file, f'my_hello_playlist{player_id}', pj.PJMEDIA_FILE_NO_LOOP)
         self.logger.info(f"Sending bot speaker, 444, player_file: {player_file}, player_id: {player_id}, isActive: {self.isActive()}")
         self.audio_player.startTransmit(self.audio_media)
+        self.agent.call_players[key].append(datetime.now().timestamp())
 
     def on_receiver_asr_result(self, message, *args):
         # 判断是否播放完成 否则不记录用户说的内容
@@ -543,6 +545,7 @@ class BotAgent:
         self.user_part_pool = queue.Queue(maxsize=len(user_part_range))
         self.accounts = {}
         self.calls = {}
+        self.call_players={}
         self.ep = pj.Endpoint()
         self.daemon_stopping = False
         self.is_stopping = False
@@ -626,17 +629,37 @@ class BotAgent:
 
     def thread_health_check(self):
         while not self.daemon_stopping:
+            _lock = self.play_complete_degree_check()
+            if _lock:
+                self.logger.error("daviddebugger::play time greater than 60s, will restart")
+                self.restart()
+                continue
+
             _lock = self.cache.get_pjsua_thread_lock()
             if _lock:
+                self.cache.del_pjsua_thread_lock()
                 self.logger.error("daviddebugger::thread is lock, will restart")
                 self.restart()
+                continue
 
             _lock = self.cache.lock_register_per_hours()
             if not _lock and len(self.accounts) == len(self.user_part_range):
                 self.logger.error("daviddebugger::register expire, will restart")
                 self.restart()
+                continue
             time.sleep(0.1)
 
+    def play_complete_degree_check(self):
+        for k, v in list(self.call_players.items()):
+            if len(v) == 2:
+                self.call_players.pop(k)
+                continue
+            if len(v) == 1:
+                sec = datetime.now().timestamp() - v[0]
+                if sec > 90:
+                    return True
+        return False
+
     def transfer(self, user_part, call_id, device_id, service_id='00000000000000000'):
         if self.acd_service:
             self.acd_service.transfer_to_agent(call_id, device_id, service_id, hold=True)
@@ -739,6 +762,7 @@ class BotAgent:
         except:
             pass
         self.logger.info("destroy, come in 22222")
+        self.call_players.clear()
         self.accounts.clear()
         self.calls.clear()
         # # Destroy the library