|
@@ -3,12 +3,15 @@
|
|
|
|
|
|
# from src.core.callcenter.views import app
|
|
|
from . import app
|
|
|
+from datetime import datetime
|
|
|
from flask import request, session
|
|
|
from flask_socketio import SocketIO, Namespace, join_room, leave_room, emit
|
|
|
from threading import Thread
|
|
|
from src.core.datasource import RedisHandler
|
|
|
import json
|
|
|
|
|
|
+from .constant import CENTER_AGENT_HEARTBEAT
|
|
|
+
|
|
|
socketio = SocketIO(app, async_mode='gevent', cors_allowed_origins="*")
|
|
|
logger = app.logger
|
|
|
redis_handler = RedisHandler()
|
|
@@ -67,7 +70,16 @@ class MyNamespace(Namespace):
|
|
|
emit('login', request.sid)
|
|
|
|
|
|
def on_heartbeat(self, heartbeat):
|
|
|
- logger.info('heartbeat received: %s %', heartbeat, type(heartbeat))
|
|
|
+ if not heartbeat:
|
|
|
+ return
|
|
|
+ data = json.loads(heartbeat)
|
|
|
+ saas_id = data.get('saas_id')
|
|
|
+ agent_id = data.get('agent_id')
|
|
|
+
|
|
|
+ now = datetime.now().timestamp()
|
|
|
+ key = CENTER_AGENT_HEARTBEAT % saas_id
|
|
|
+ redis_handler.redis.hset(key, agent_id, now)
|
|
|
+ logger.info('heartbeat received: %s %s', heartbeat, type(heartbeat))
|
|
|
pass
|
|
|
|
|
|
def on_OnPrompt(self, event):
|