|
@@ -258,12 +258,36 @@ class AgentOperService:
|
|
|
def __init__(self, app):
|
|
|
self.app = app
|
|
|
self.logger = app.logger
|
|
|
+ self.redis_handler = RedisHandler()
|
|
|
self.push_handler = PushHandler(app.logger)
|
|
|
self.data_handle_server = DataHandleServer(app)
|
|
|
self.agent_monitor_service = AgentMonitorService(app)
|
|
|
self.agent_actionlog_service = AgentActionLogService(app)
|
|
|
self.agent_state_service = AgentStateService(app)
|
|
|
|
|
|
+ self.daemon_stopping = False
|
|
|
+ self.agent_heartbeat_expire = 30
|
|
|
+ threading.Thread(target=self.agent_heartbeat_daemon).start()
|
|
|
+
|
|
|
+ def agent_heartbeat_daemon(self):
|
|
|
+ def check_out_daemon(_name, key, value):
|
|
|
+ try:
|
|
|
+ sec = datetime.now().timestamp() - float(value)
|
|
|
+ if sec > self.agent_heartbeat_expire:
|
|
|
+ self.redis_handler.redis.hdel(_name, key)
|
|
|
+ self.logger.error("agent heartbeat expired, will checkout %s %s", key, value)
|
|
|
+ self.checkout(AgentActionRequest(saas_id=SAAS_ID, agent_id=key, agent_number=key))
|
|
|
+ except:
|
|
|
+ traceback.print_exc()
|
|
|
+
|
|
|
+ while not self.daemon_stopping:
|
|
|
+ name = CENTER_AGENT_HEARTBEAT % SAAS_ID
|
|
|
+ members = self.redis_handler.redis.hgetall(name)
|
|
|
+ if not members:
|
|
|
+ continue
|
|
|
+ for k,v in members.items():
|
|
|
+ check_out_daemon(name, k, v)
|
|
|
+
|
|
|
@with_app_context
|
|
|
def enable(self, req: AgentActionRequest):
|
|
|
agent = self.data_handle_server.get_agent(req.saas_id, req.agent_number, req.out_id)
|
|
@@ -773,23 +797,6 @@ class AgentStateService:
|
|
|
self.agent_monitor_service = AgentMonitorService(app)
|
|
|
self.agent_actionlog_service = AgentActionLogService(app)
|
|
|
|
|
|
- self.daemon_stopping = False
|
|
|
- self.agent_heartbeat_expire = 30
|
|
|
- threading.Thread(target=self.agent_heartbeat_daemon).start()
|
|
|
-
|
|
|
- def agent_heartbeat_daemon(self):
|
|
|
- while not self.daemon_stopping:
|
|
|
- key = CENTER_AGENT_HEARTBEAT % SAAS_ID
|
|
|
- members = self.redis_handler.redis.hgetall(key)
|
|
|
- if not members:
|
|
|
- continue
|
|
|
- for k, v in members.items():
|
|
|
- sec = datetime.now().timestamp() - float(v)
|
|
|
- if sec > self.agent_heartbeat_expire:
|
|
|
- self.redis_handler.redis.hdel(key, k)
|
|
|
- self.logger.error("agent heartbeat expired, %s %s", k, v)
|
|
|
- self.busy(SAAS_ID, k, k)
|
|
|
-
|
|
|
def idle(self, saas_id, agent_id, phone_num):
|
|
|
human_service = self.data_handle_server.get_human_service_service(saas_id, agent_id)
|
|
|
if human_service is None:
|