Browse Source

Merge branch 'develop' of ssh://gitlab.fuxicarbon.com:1111/client_service/voice-gateway-service into develop

shanghui 3 months ago
parent
commit
f497ac58da
2 changed files with 23 additions and 15 deletions
  1. 1 1
      src/core/callcenter/cache.py
  2. 22 14
      src/core/voip/bot.py

+ 1 - 1
src/core/callcenter/cache.py

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

+ 22 - 14
src/core/voip/bot.py

@@ -330,9 +330,9 @@ class MyCall(pj.Call):
             self.logger.info(f"Sending bot speaker, 222, player_file: {player_file}, player_id: {player_id}, isActive: {self.isActive()}")
             self.audio_player.createPlayer(player_file[0], pj.PJMEDIA_FILE_NO_LOOP)
         else:
-            self.logger.info(f"Sending bot speaker, 222, player_file: {player_file}, player_id: {player_id}, isActive: {self.isActive()}")
+            self.logger.info(f"Sending bot speaker, 333, player_file: {player_file}, player_id: {player_id}, isActive: {self.isActive()}")
             self.audio_player.createPlaylist(player_file, f'my_hello_playlist{player_id}', pj.PJMEDIA_FILE_NO_LOOP)
-        self.logger.info(f"Sending bot speaker, 333, player_file: {player_file}, player_id: {player_id}, isActive: {self.isActive()}")
+        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)
 
     def on_receiver_asr_result(self, message, *args):
@@ -544,6 +544,7 @@ class BotAgent:
         self.accounts = {}
         self.calls = {}
         self.ep = pj.Endpoint()
+        self.daemon_stopping = False
         self.is_stopping = False
         self.counter = 0
         self.acd_service = None
@@ -551,6 +552,7 @@ class BotAgent:
         self.dataHandleServer = DataHandleServer(app)
         self.pjsua_thread = None
         self.start()
+        threading.Thread(target=self.thread_health_check).start()
 
     def create_pjsua2(self, timeout_sec=86400):
         start_time = time.time()
@@ -616,19 +618,24 @@ class BotAgent:
 
         while not self.is_stopping:
             registry.BOT_AGENT_LIVES.set(self.user_part_pool.qsize())
-            self.thread_health_check()
+            # self.thread_health_check()
             self.ep.libHandleEvents(50)
 
-    def thread_health_check(self):
-        _lock = self.cache.get_pjsua_thread_lock()
-        if _lock:
-            self.logger.error("daviddebugger::thread is lock, will restart")
-            self.restart()
+        # Destroy the library
+        self.ep.libDestroy()
 
-        _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()
+    def thread_health_check(self):
+        while not self.daemon_stopping:
+            _lock = self.cache.get_pjsua_thread_lock()
+            if _lock:
+                self.logger.error("daviddebugger::thread is lock, will restart")
+                self.restart()
+
+            _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()
+            time.sleep(0.1)
 
     def transfer(self, user_part, call_id, device_id, service_id='00000000000000000'):
         if self.acd_service:
@@ -734,8 +741,8 @@ class BotAgent:
         self.logger.info("destroy, come in 22222")
         self.accounts.clear()
         self.calls.clear()
-        # Destroy the library
-        self.ep.libDestroy()
+        # # Destroy the library
+        # self.ep.libDestroy()
         self.logger.info("destroy, come in 33333")
 
         if not self.pjsua_thread.is_alive():
@@ -756,6 +763,7 @@ class BotAgent:
 
     def __del__(self):
         self.destroy()
+        self.daemon_stopping = True
 
 
 # if __name__ == '__main__':