DavidLiu před 4 měsíci
rodič
revize
b84b0b9200
2 změnil soubory, kde provedl 67 přidání a 36 odebrání
  1. 35 0
      src/core/callcenter/dao.py
  2. 32 36
      src/core/callcenter/esl/client.py

+ 35 - 0
src/core/callcenter/dao.py

@@ -5,6 +5,41 @@ import json
 from . import db
 from datetime import datetime
 
+class Bucket(db.Model):
+    __tablename__ = 'c_bucket'
+    __table_args__ = {
+        'comment': '流量分桶表',
+        'mysql_engine': 'InnoDB',
+        'mysql_charset': 'utf8mb4'
+    }
+
+    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
+    name = db.Column(db.String(32), nullable=False, default='', comment='名称')
+    eid = db.Column(db.String(16), nullable=False, default='', comment='实验id')
+    lower = db.Column(db.String(32), nullable=False, default='', comment='下限')
+    upper = db.Column(db.String(64), nullable=False, default='', comment='上限')
+    config = db.Column(db.String(100), nullable=False, default='', comment='拓展配置')
+    update_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow, comment='更新时间')
+    create_time = db.Column(db.TIMESTAMP, nullable=False, default=datetime.utcnow, comment='创建时间' )
+
+    __table_args__ = (
+        db.Index('idx_eid', 'eid', mysql_using='BTREE'),
+    )
+
+    def __repr__(self):
+        return json.dumps(self.to_dict())
+
+    def to_dict(self):
+        return {
+            'id': self.id,
+            'name': self.name,
+            'eid': self.eid,
+            'lower': self.lower,
+            'upper': self.upper,
+            'config': self.config,
+            'update_time': self.update_time.isoformat() if self.update_time else None,
+            'create_time': self.create_time.isoformat() if self.create_time else None,
+        }
 
 class Agent(db.Model):
     __tablename__ = 'c_agent'

+ 32 - 36
src/core/callcenter/esl/client.py

@@ -482,40 +482,10 @@ class OutboundClient:
     def __init__(self, agent, app):
         self.app = app
         self.logger = app.logger
-        self.whitelist = []
-        self.update_whitelist()  # 初始化加载白名单
-
-        # 定时更新白名单
-        threading.Thread(target=self.refresh_whitelist, daemon=True).start()
-
-
-        self.dataHandleServer = DataHandleServer(app)
-        #threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent, logger)).start()
         server_thread = threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent))
         server_thread.daemon = True  # 设置守护线程
         server_thread.start()
 
-    def update_whitelist(self):
-        with self.app.app_context():
-            phones = Whitelist.query.filter_by(del_flag=0).all()
-            self.whitelist = [phone.phone for phone in phones]
-            self.logger.info("Whitelist updated: %s", self.whitelist)
-
-    def refresh_whitelist(self):
-        while True:
-            time.sleep(3600) # 每 1小时 更新一次
-            self.update_whitelist()
-
-    def load_whitelist(self):
-        return self.whitelist
-
-    def load_agent_monitor(self):
-        with self.app.app_context():
-            agents = AgentMonitor.query.filter_by(check_state=0,service_state=2).all()
-            agent_nums = [agent.agent_num for agent in agents]
-            return agent_nums
-
-
     class ESLRequestHandler(socketserver.BaseRequestHandler):
         def setup(self):
             try:
@@ -618,18 +588,44 @@ class OutboundClient:
 
 
     class CustomTCPServer(socketserver.TCPServer):
-        def __init__(self, server_address, RequestHandlerClass, agent, app,whitelist_loader,load_agent_monitor,dataHandleServer):
+        def __init__(self, server_address, RequestHandlerClass, agent, app):
+            super().__init__(server_address, RequestHandlerClass)
             self.agent = agent
+            self.app = app
             self.cache = Cache(app)
             self.logger = app.logger
-            self.load_whitelist = whitelist_loader
-            self.load_agent_monitor = load_agent_monitor
-            self.dataHandleServer = dataHandleServer
-            super().__init__(server_address, RequestHandlerClass)
+            self.whitelist = []
+            self.update_whitelist()  # 初始化加载白名单
+            self.dataHandleServer = DataHandleServer(app)
+            # 定时更新白名单
+            threading.Thread(target=self.refresh_whitelist, daemon=True).start()
+
+        def update_whitelist(self):
+            with self.app.app_context():
+                phones = Whitelist.query.filter_by(del_flag=0).all()
+                self.whitelist = [phone.phone for phone in phones]
+                self.logger.info("Whitelist updated: %s", self.whitelist)
+
+
+        def refresh_whitelist(self):
+            while True:
+                time.sleep(3600)  # 每 1小时 更新一次
+                self.update_whitelist()
+
+
+        def load_whitelist(self):
+            return self.whitelist
+
+
+        def load_agent_monitor(self):
+            with self.app.app_context():
+                agents = AgentMonitor.query.filter_by(check_state=0, service_state=2).all()
+                agent_nums = [agent.agent_num for agent in agents]
+                return agent_nums
 
     def start(self, HOST='0.0.0.0', PORT=8084, agent=None):
         # HOST, PORT = "0.0.0.0", 8084
         # 创建一个 TCP 服务器
-        with self.CustomTCPServer((HOST, PORT), self.ESLRequestHandler, agent, self.app, self.load_whitelist, self.load_agent_monitor,self.dataHandleServer) as server:
+        with self.CustomTCPServer((HOST, PORT), self.ESLRequestHandler, agent, self.app) as server:
             print(f"ESL server listening on {HOST}:{PORT}")
             server.serve_forever()