C:/Program Files/Git/api/events加入socketio机制——更新超时时间
This commit is contained in:
12
app.py
12
app.py
@@ -251,7 +251,9 @@ socketio = SocketIO(
|
||||
"https://valuefrontier.cn", "http://valuefrontier.cn"],
|
||||
async_mode='gevent',
|
||||
logger=True,
|
||||
engineio_logger=False
|
||||
engineio_logger=False,
|
||||
ping_timeout=120, # 心跳超时时间(秒),客户端120秒内无响应才断开
|
||||
ping_interval=25 # 心跳检测间隔(秒),每25秒发送一次ping
|
||||
)
|
||||
|
||||
|
||||
@@ -7583,7 +7585,7 @@ last_checked_event_id = 0
|
||||
def poll_new_events():
|
||||
"""
|
||||
定期轮询数据库,检查是否有新事件
|
||||
每 2 分钟执行一次
|
||||
每 30 秒执行一次
|
||||
"""
|
||||
global last_checked_event_id
|
||||
|
||||
@@ -7629,17 +7631,17 @@ def initialize_event_polling():
|
||||
|
||||
# 创建后台调度器
|
||||
scheduler = BackgroundScheduler()
|
||||
# 每 2 分钟执行一次轮询
|
||||
# 每 30 秒执行一次轮询
|
||||
scheduler.add_job(
|
||||
func=poll_new_events,
|
||||
trigger='interval',
|
||||
minutes=2,
|
||||
seconds=30,
|
||||
id='poll_new_events',
|
||||
name='检查新事件并推送',
|
||||
replace_existing=True
|
||||
)
|
||||
scheduler.start()
|
||||
print('[轮询] 调度器已启动,每 2 分钟检查一次新事件')
|
||||
print('[轮询] 调度器已启动,每 30 秒检查一次新事件')
|
||||
|
||||
except Exception as e:
|
||||
print(f'[轮询] 初始化失败: {e}')
|
||||
|
||||
Reference in New Issue
Block a user