From 8e183015de20a8fb84d00b466e18bdf2850b1b43 Mon Sep 17 00:00:00 2001 From: Sydonian <794346190@qq.com> Date: Thu, 4 Sep 2025 16:51:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8C=E6=AD=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=9C=A8=E9=9B=86=E7=BE=A4=E4=B8=8B=E7=9A=84=E6=95=88?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/internal/spacesyncer/space_syncer.go | 5 ----- client/internal/spacesyncer/trigger.go | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/client/internal/spacesyncer/space_syncer.go b/client/internal/spacesyncer/space_syncer.go index 252ee3b..e7affe0 100644 --- a/client/internal/spacesyncer/space_syncer.go +++ b/client/internal/spacesyncer/space_syncer.go @@ -49,11 +49,6 @@ func (s *SpaceSyncer) Start() *async.UnboundChannel[SpaceSyncerEvent] { ch := async.NewUnboundChannel[SpaceSyncerEvent]() - if !s.cluster.IsMaster() { - log.Infof("not master, skip start space syncer") - return ch - } - allTask, err := db.DoTx01(s.db, s.db.SpaceSyncTask().GetAll) if err != nil { log.Warnf("load task from db: %v", err) diff --git a/client/internal/spacesyncer/trigger.go b/client/internal/spacesyncer/trigger.go index 7aab378..f257413 100644 --- a/client/internal/spacesyncer/trigger.go +++ b/client/internal/spacesyncer/trigger.go @@ -11,6 +11,12 @@ import ( func triggerOnce(syncer *SpaceSyncer, task *task) { go func() { log := logger.WithField("Mod", logMod) + + if !syncer.cluster.IsMaster() { + log.Infof("not cluster master, skip") + return + } + execute(syncer, task) syncer.lock.Lock() @@ -42,6 +48,11 @@ func triggerInterval(syncer *SpaceSyncer, task *task, trigger *jcstypes.SpaceSyn for { select { case <-ticker.C: + if !syncer.cluster.IsMaster() { + log.Infof("not cluster master, skip") + continue + } + execute(syncer, task) case <-task.Context.Done(): break loop @@ -83,6 +94,11 @@ func triggerAt(syncer *SpaceSyncer, task *task, trigger *jcstypes.SpaceSyncTrigg select { case <-time.After(at.Sub(nowTime)): + if !syncer.cluster.IsMaster() { + log.Infof("not cluster master, skip") + continue + } + execute(syncer, task) case <-task.Context.Done():