Explorar el Código

callback event serial

DavidLiu hace 3 meses
padre
commit
4524da8cd7
Se han modificado 3 ficheros con 13 adiciones y 11 borrados
  1. 3 10
      src/core/callcenter/callback.py
  2. 3 1
      src/core/callcenter/registry.py
  3. 7 0
      src/core/callcenter/views.py

+ 3 - 10
src/core/callcenter/callback.py

@@ -30,7 +30,7 @@ class Callback(object):
             try:
                 event, call_info, device_info = self.event_queue.get(timeout=1)
                 call_type = CallType.get_by_code(call_info.call_type) if call_info else None
-                self.logger.info("callback::call_type=%s, call_info=%s", call_type, call_info)
+                # self.logger.info("callback::call_type=%s, call_info=%s", call_type, call_info)
                 if call_type is None:
                     continue
                 if CallType.BOT_CALL == call_type:
@@ -46,6 +46,7 @@ class Callback(object):
         for k, v in self.executors.items():
             v.shutdown()
 
+
     def callback_event(self, event):
         event_name = EslEventUtil.getEventName(event)
         # CUSTOM == event_name or
@@ -63,14 +64,6 @@ class Callback(object):
         self.logger.info("callback::event_name=%s, call_id=%s, device_id=%s", event_name, call_id, device_id)
         self.event_queue.put_nowait((event, call_info, device_info))
 
-        # call_type = CallType.get_by_code(call_info.call_type) if call_info else None
-        # # self.logger.info("callback::event_name=%s, call_type=%s, call_id=%s, device_id=%s, call_info=%s", event_name, call_type, call_id, device_id, call_info)
-        # if CallType.BOT_CALL == call_type:
-        #     threading.Thread(target=self.agent_event_service.bot_event_channel, args=(event, call_info, device_info)).start()
-        #     # self.agent_event_service.bot_event_channel(event, call_info, device_info)
-        # else:
-        #     threading.Thread(target=self.agent_event_service.agent_event_channel, args=(event, call_info, device_info)).start()
-        #     # self.agent_event_service.agent_event_channel(event, call_info, device_info)
 
     def choose_thread_pool_executor(self, e):
         call_id = EslEventUtil.getCallId(e)
@@ -81,5 +74,5 @@ class Callback(object):
             random_index = abs(mmh3.hash(random_id)) % len(self.executors)
         else:
             random_index = random.randint(0, len(self.executors) - 1) if self.executors else 0
-        self.logger.info('choose_thread_pool_executor.index %s %s %s %s', random_index, call_id, device_id, wdh_device_id)
+        # self.logger.info('choose_thread_pool_executor.index %s %s %s %s', random_index, call_id, device_id, wdh_device_id)
         return self.executors.get(random_index)

+ 3 - 1
src/core/callcenter/registry.py

@@ -18,4 +18,6 @@ CALL_BOT_HANGUP_REQUESTS = Counter('call_bot_hangup_requests', '机器挂机量'
 
 # esl时间耗时
 ESL_EVENT_LATENCY = Histogram('esl_event_latency', 'Esl Event latency in seconds', ['eventName'])
-ESL_EVENT_CALLBACK_LATENCY = Histogram('esl_event_callback_latency', 'Esl Event callback latency in seconds', ['eventName','callType'])
+ESL_EVENT_CALLBACK_LATENCY = Histogram('esl_event_callback_latency', 'Esl Event callback latency in seconds', ['eventName','callType'])
+
+FLASK_ACTIVE_THREADS = Gauge('flask_active_threads', 'Number of active threads')

+ 7 - 0
src/core/callcenter/views.py

@@ -1,5 +1,7 @@
 #!/usr/bin/env python3
 # encoding:utf-8
+import threading
+
 from flask import request, render_template_string
 
 from src.core.callcenter.agent import AgentService, AgentOperService
@@ -11,6 +13,7 @@ from src.core.callcenter.esl.client import InboundClient, OutboundClient
 from src.core.voip.bot import BotAgent
 from . import app
 from .acd import AcdService
+from src.core.callcenter import registry
 
 agent = BotAgent(app)
 inbound_client = InboundClient(agent,app)
@@ -22,6 +25,10 @@ acd_service = AcdService(inbound_client, app)
 agent.acd_service = acd_service
 
 
+@app.before_request
+def before_request():
+    registry.FLASK_ACTIVE_THREADS.set(threading.active_count())
+
 @app.route('/')
 def index():
     return render_template_string("""<!DOCTYPE html>