1、优化websocket连接
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user