1、优化websocket连接

This commit is contained in:
2025-09-19 15:42:51 +08:00
parent 7adba048c8
commit 556a32cb7c
4 changed files with 331 additions and 103 deletions

View File

@ -86,6 +86,10 @@ func run() error {
clearLogJob(db, ctx)
})
//自动重启websocket
utility.SafeGo(func() {
reconnect(ctx)
})
// 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
@ -133,3 +137,18 @@ func clearLogJob(db *gorm.DB, ctx context.Context) {
fileservice.ClearLogs(db)
}
}
// 定时重连websocket
func reconnect(ctx context.Context) error {
ticker := time.NewTicker(time.Hour * 1)
defer ticker.Stop()
select {
case <-ctx.Done():
return nil
case <-ticker.C:
serverinit.RestartConnect()
}
return nil
}