From 662b889310530ec9643fa65d75de337d47a61b6e Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 10 十一月 2023 17:47:05 +0800 Subject: [PATCH] 切换设备时异步重启定时任务 --- api/v1/device.go | 11 ++++------- crontask/cron_task.go | 8 +++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/api/v1/device.go b/api/v1/device.go index e2d0385..04ef6f9 100644 --- a/api/v1/device.go +++ b/api/v1/device.go @@ -10,6 +10,7 @@ "apsClient/pkg/contextx" "apsClient/pkg/ecode" "apsClient/pkg/logx" + "apsClient/pkg/safe" "apsClient/service" "github.com/gin-gonic/gin" ) @@ -46,13 +47,9 @@ } service.SetDeviceIDToFile(params.CurrentDeviceID) conf.Conf.CurrentDeviceID = params.CurrentDeviceID - err = crontask.RestartTask(conf.Conf.SerfClusterStatus != constvar.SerfClusterStatusSlave) - if err != nil { - logx.Errorf("restart task failed:%v", err) - ctx.Fail(ecode.UnknownErr) - return - } - + safe.Go(func() { + _ = crontask.RestartTask(conf.Conf.SerfClusterStatus != constvar.SerfClusterStatusSlave) + }) ctx.Ok() } diff --git a/crontask/cron_task.go b/crontask/cron_task.go index 153182a..c38ef9d 100644 --- a/crontask/cron_task.go +++ b/crontask/cron_task.go @@ -143,7 +143,13 @@ s.Stop() s.Clear() } - return StartTask(isMaster) + err := StartTask(isMaster) + if err != nil { + logx.Errorf("restart task failed:%v", err) + return err + } + logx.Infof("restart task ok, isMaster:", isMaster) + return nil } // Once 涓�娆℃�т换鍔� -- Gitblit v1.8.0