mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-25 12:27:13 +00:00
fix(warp): surface update-clock persistence failures (#6209)
Co-authored-by: n0ctal <293235942+n0ctal@users.noreply.github.com>
This commit is contained in:
@@ -28,13 +28,19 @@ func (j *WarpIpJob) Run() {
|
||||
return
|
||||
}
|
||||
|
||||
lastUpdate, _ := j.settingService.GetWarpLastUpdate()
|
||||
lastUpdate, err := j.settingService.GetWarpLastUpdate()
|
||||
if err != nil {
|
||||
logger.Warning("Failed to read scheduled WARP IP update time: ", err)
|
||||
return
|
||||
}
|
||||
now := time.Now().Unix()
|
||||
|
||||
// First run after the feature is enabled (e.g. interval set via direct
|
||||
// DB edit): establish a baseline instead of rotating immediately.
|
||||
if lastUpdate == 0 {
|
||||
_ = j.settingService.SetWarpLastUpdate(now)
|
||||
if err := j.settingService.SetWarpLastUpdate(now); err != nil {
|
||||
logger.Warning("Failed to establish scheduled WARP IP update time: ", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -46,7 +52,9 @@ func (j *WarpIpJob) Run() {
|
||||
return
|
||||
}
|
||||
|
||||
_ = j.settingService.SetWarpLastUpdate(now)
|
||||
if err := j.settingService.SetWarpLastUpdate(now); err != nil {
|
||||
logger.Warning("WARP IP changed but the next-update time was not saved: ", err)
|
||||
}
|
||||
j.xrayService.SetToNeedRestart()
|
||||
logger.Info("Successfully updated WARP IP and scheduled Xray restart")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package job
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/web/service"
|
||||
)
|
||||
|
||||
func TestWarpIpJobInitializesMissingLastUpdate(t *testing.T) {
|
||||
setupIntegrationDB(t)
|
||||
|
||||
settings := service.SettingService{}
|
||||
if err := settings.SetWarpUpdateInterval(1); err != nil {
|
||||
t.Fatalf("enable scheduled WARP rotation: %v", err)
|
||||
}
|
||||
|
||||
job := &WarpIpJob{settingService: settings}
|
||||
job.Run()
|
||||
|
||||
var stored model.Setting
|
||||
if err := database.GetDB().Where("key = ?", "warpLastUpdate").First(&stored).Error; err != nil {
|
||||
t.Fatalf("scheduled WARP rotation did not establish its baseline: %v", err)
|
||||
}
|
||||
if stored.Value == "" || stored.Value == "0" {
|
||||
t.Fatalf("warpLastUpdate = %q, want a non-zero baseline", stored.Value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user