From 4c24c4274c5d007e0c1edff8ffd71cf8e87e8c9c Mon Sep 17 00:00:00 2001 From: ayflying Date: Mon, 31 Mar 2025 14:57:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=E5=8F=AA=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E5=90=AF=E5=8A=A8=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/logic/systemCron/systemCron.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/logic/systemCron/systemCron.go b/internal/logic/systemCron/systemCron.go index de53fa1..1d7324d 100644 --- a/internal/logic/systemCron/systemCron.go +++ b/internal/logic/systemCron/systemCron.go @@ -7,13 +7,15 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gcron" "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/os/gtimer" "sync" "time" ) var ( - ctx = gctx.New() + ctx = gctx.New() + startTime *gtime.Time ) // sSystemCron 结构体定义了系统定时任务的秒计时器。 @@ -110,6 +112,12 @@ func (s *sSystemCron) AddCron(typ v1.CronType, _func func() error) { // @receiver s // @return err func (s *sSystemCron) StartCron() (err error) { + //预防重复启动 + if startTime != nil { + return + } + startTime = gtime.Now() + g.Log().Debug(ctx, "启动计划任务定时器详情") //每秒任务 gtimer.SetInterval(ctx, time.Second, func(ctx context.Context) {