Bladeren bron

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

shanghui 3 maanden geleden
bovenliggende
commit
61a88b64ee
2 gewijzigde bestanden met toevoegingen van 6 en 7 verwijderingen
  1. 2 2
      src/core/callcenter/cache.py
  2. 4 5
      src/core/voip/bot.py

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

@@ -194,6 +194,6 @@ class Cache:
         key = BOT_REGISTER_PER_HOURS %hour
         return self.redis_handler.redis.get(key)
 
-    def set_register_per_hours(self, hour):
+    def set_register_per_hours(self, hour, expire=86400):
         key = BOT_REGISTER_PER_HOURS %hour
-        return self.redis_handler.redis.set(key, "1", ex=60*60, nx=True)
+        return self.redis_handler.redis.set(key, "1", ex=expire, nx=True)

+ 4 - 5
src/core/voip/bot.py

@@ -549,11 +549,11 @@ class BotAgent:
             self.register_per_hours()
             self.ep.libHandleEvents(100)
 
-    def create_account(self, recreate = False):
+    def create_account(self, recreate = False, timeout_sec=86400):
         start_time = time.time()
         try:
             _hour = datetime.now().strftime('%Y%m%d%H')
-            self.cache.set_register_per_hours(_hour)
+            self.cache.set_register_per_hours(_hour, expire=timeout_sec)
             if recreate:
                 for k, v in self.accounts.items():
                     try:
@@ -573,7 +573,7 @@ class BotAgent:
                 cred = pj.AuthCredInfo("digest", "*", f"{user_part}", 0, self.password)
                 acfg.sipConfig.authCreds.append(cred)
 
-                acfg.regConfig.timeoutSec = 86400  # 注册超时时间(秒)
+                acfg.regConfig.timeoutSec = timeout_sec  # 注册超时时间(秒)
                 acfg.regConfig.retryIntervalSec = 10  # 重试间隔时间(秒)
                 acfg.regConfig.firstRetryIntervalSec = 10  # 首次重试间隔时间(秒)
 
@@ -599,8 +599,7 @@ class BotAgent:
     def register_per_hours(self):
         _hour = datetime.now().strftime('%Y%m%d%H')
         _lock = self.cache.lock_register_per_hours(_hour)
-        if _lock and len(self.accounts) == len(self.user_part_range):
-            self.cache.set_register_per_hours(_hour)
+        if not _lock and len(self.accounts) == len(self.user_part_range):
             self.create_account(recreate=True)
 
     def transfer(self, user_part, call_id, device_id, service_id='00000000000000000'):