Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2023-09-06 17:52:37 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-09-06 17:52:37 +0300
commitbe4a68bd8bbd0a79e8195a3e1dd73062e9c1663a (patch)
tree711df68ec2bf7c29d8e6f2ec336df824e3cede38
parent4e6484caec87b44e3659281eb74e497bb450ade5 (diff)
move restart cron to web.go
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
-rw-r--r--web/controller/inbound.go16
-rw-r--r--web/web.go10
2 files changed, 10 insertions, 16 deletions
diff --git a/web/controller/inbound.go b/web/controller/inbound.go
index 219f1211..8b64fe6e 100644
--- a/web/controller/inbound.go
+++ b/web/controller/inbound.go
@@ -4,8 +4,6 @@ import (
"fmt"
"strconv"
"x-ui/database/model"
- "x-ui/logger"
- "x-ui/web/global"
"x-ui/web/service"
"x-ui/web/session"
@@ -20,7 +18,6 @@ type InboundController struct {
func NewInboundController(g *gin.RouterGroup) *InboundController {
a := &InboundController{}
a.initRouter(g)
- a.startTask()
return a
}
@@ -42,19 +39,6 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
g.POST("/delDepletedClients/:id", a.delDepletedClients)
}
-func (a *InboundController) startTask() {
- webServer := global.GetWebServer()
- c := webServer.GetCron()
- c.AddFunc("@every 10s", func() {
- if a.xrayService.IsNeedRestartAndSetFalse() {
- err := a.xrayService.RestartXray(false)
- if err != nil {
- logger.Error("restart xray failed:", err)
- }
- }
- })
-}
-
func (a *InboundController) getInbounds(c *gin.Context) {
user := session.GetLoginUser(c)
inbounds, err := a.inboundService.GetInbounds(user.Id)
diff --git a/web/web.go b/web/web.go
index c3a88b66..abf2d6c1 100644
--- a/web/web.go
+++ b/web/web.go
@@ -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