Browse Source

修改同步功能在集群下的效果

master
Sydonian 2 months ago
parent
commit
8e183015de
2 changed files with 16 additions and 5 deletions
  1. +0
    -5
      client/internal/spacesyncer/space_syncer.go
  2. +16
    -0
      client/internal/spacesyncer/trigger.go

+ 0
- 5
client/internal/spacesyncer/space_syncer.go View File

@@ -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)


+ 16
- 0
client/internal/spacesyncer/trigger.go View File

@@ -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():


Loading…
Cancel
Save