Skip to content

Commit

Permalink
cloudaccounts: one sync task in queue per cloudaccount
Browse files Browse the repository at this point in the history
  • Loading branch information
yousong committed Jun 18, 2020
1 parent eb5e902 commit 8f5c65b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/compute/models/cloudaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"

"yunion.io/x/jsonutils"
Expand Down Expand Up @@ -2340,8 +2341,26 @@ func (account *SCloudaccount) markAutoSync(userCred mcclient.TokenCredential) er
return nil
}

var (
cloudaccountPendingSyncs = map[string]struct{}{}
cloudaccountPendingSyncsMutex = &sync.Mutex{}
)

func (account *SCloudaccount) SubmitSyncAccountTask(ctx context.Context, userCred mcclient.TokenCredential, waitChan chan error, autoSync bool) {
cloudaccountPendingSyncsMutex.Lock()
defer cloudaccountPendingSyncsMutex.Unlock()
if _, ok := cloudaccountPendingSyncs[account.Id]; ok {
return
}
cloudaccountPendingSyncs[account.Id] = struct{}{}

RunSyncCloudAccountTask(func() {
func() {
cloudaccountPendingSyncsMutex.Lock()
defer cloudaccountPendingSyncsMutex.Unlock()
delete(cloudaccountPendingSyncs, account.Id)
}()

log.Debugf("syncAccountStatus %s %s", account.Id, account.Name)
err := account.syncAccountStatus(ctx, userCred)
if waitChan != nil {
Expand All @@ -2356,7 +2375,8 @@ func (account *SCloudaccount) SubmitSyncAccountTask(ctx context.Context, userCre
account.markAutoSync(userCred)
providers := account.GetEnabledCloudproviders()
for i := range providers {
providers[i].syncCloudproviderRegions(ctx, userCred, syncRange, nil, autoSync)
provider := &providers[i]
provider.syncCloudproviderRegions(ctx, userCred, syncRange, nil, autoSync)
syncCnt += 1
}
}
Expand Down

0 comments on commit 8f5c65b

Please sign in to comment.