cloudaccounts: one sync task in queue per cloudaccount

This commit is contained in:
Yousong Zhou
2020-06-16 17:57:49 +08:00
parent 4abbfd9932
commit 2ccc45df92
+21 -1
View File
@@ -21,6 +21,7 @@ import (
"net/url"
"strconv"
"strings"
"sync"
"time"
"yunion.io/x/jsonutils"
@@ -1876,8 +1877,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 {
@@ -1892,7 +1911,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
}
}