fix(warp): surface update-clock persistence failures (#6209)

Co-authored-by: n0ctal <293235942+n0ctal@users.noreply.github.com>
This commit is contained in:
n0ctal
2026-08-13 15:31:05 +05:00
committed by GitHub
parent 79ef85b59f
commit 64f4f0746c
5 changed files with 122 additions and 8 deletions
+11 -3
View File
@@ -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")
}
+29
View File
@@ -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)
}
}