move restart cron to web.go

Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
This commit is contained in:
MHSanaei
2023-09-06 18:22:37 +03:30
parent 4e6484caec
commit be4a68bd8b
2 changed files with 10 additions and 16 deletions

View File

@@ -241,6 +241,16 @@ func (s *Server) startTask() {
// Check whether xray is running every 30 seconds
s.cron.AddJob("@every 30s", job.NewCheckXrayRunningJob())
// Check if xray needs to be restarted
s.cron.AddFunc("@every 10s", func() {
if s.xrayService.IsNeedRestartAndSetFalse() {
err := s.xrayService.RestartXray(false)
if err != nil {
logger.Error("restart xray failed:", err)
}
}
})
go func() {
time.Sleep(time.Second * 5)
// Statistics every 10 seconds, start the delay for 5 seconds for the first time, and staggered with the time to restart xray