Skip to content

Commit

Permalink
fix(cloudmon): 避免cloudmon任务堆积导致大量请求 (#21046)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Aug 19, 2024
1 parent eda4801 commit d9be428
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pkg/cloudmon/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,16 @@ func (self *SResources) Init(ctx context.Context, userCred mcclient.TokenCredent
}
}

var incrementSync = false

func (self *SResources) IncrementSync(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
if isStart {
if isStart || incrementSync {
return
}
incrementSync = true
defer func() {
incrementSync = false
}()
err := func() error {
errs := []error{}
err := self.Cloudaccounts.increment(ctx)
Expand Down Expand Up @@ -516,10 +522,16 @@ func (self *SResources) IncrementSync(ctx context.Context, userCred mcclient.Tok
}
}

var decrementSync = false

func (self *SResources) DecrementSync(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
if isStart {
if isStart || decrementSync {
return
}
decrementSync = true
defer func() {
decrementSync = false
}()
err := func() error {
errs := []error{}
err := self.Cloudaccounts.decrement(ctx)
Expand Down Expand Up @@ -585,10 +597,16 @@ func (self *SResources) DecrementSync(ctx context.Context, userCred mcclient.Tok
}
}

var updateSync = false

func (self *SResources) UpdateSync(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
if isStart {
if isStart || updateSync {
return
}
updateSync = true
defer func() {
updateSync = false
}()
err := func() error {
errs := []error{}
err := self.Cloudaccounts.update(ctx)
Expand Down

0 comments on commit d9be428

Please sign in to comment.