From 8fcd3ef46d88e5c0ca50550581a967cd18cc90ce Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Thu, 26 Dec 2019 22:16:23 +0800 Subject: [PATCH] fix: refresh quota usage may timeout --- pkg/cloudcommon/db/quotas/handler.go | 4 +++- pkg/cloudcommon/db/quotas/usageworker.go | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/cloudcommon/db/quotas/handler.go b/pkg/cloudcommon/db/quotas/handler.go index 12dfd07c87..2a93e9083a 100644 --- a/pkg/cloudcommon/db/quotas/handler.go +++ b/pkg/cloudcommon/db/quotas/handler.go @@ -124,7 +124,9 @@ func (manager *SQuotaBaseManager) queryQuota(ctx context.Context, quota IQuota, ret.Update(jsonutils.Marshal(keys)) ret.Update(quota.ToJSON("")) - ret.Update(usage.ToJSON("usage")) + if usage != nil { + ret.Update(usage.ToJSON("usage")) + } if len(pendings) > 0 { pendingArray := jsonutils.NewArray() for _, q := range pendings { diff --git a/pkg/cloudcommon/db/quotas/usageworker.go b/pkg/cloudcommon/db/quotas/usageworker.go index 743f54893f..d36598dc06 100644 --- a/pkg/cloudcommon/db/quotas/usageworker.go +++ b/pkg/cloudcommon/db/quotas/usageworker.go @@ -74,15 +74,23 @@ func (manager *SQuotaBaseManager) PostUsageJob(keys IQuotaKeys, usageChan chan I worker.Run(func() { ctx := context.Background() + usage := manager.newQuota() + if !isDirty(key) { + if usageChan != nil { + manager.usageStore.GetQuota(ctx, keys, usage) + usageChan <- usage + } return } - clearDirty(key) - usage := manager.newQuota() usage.SetKeys(keys) err := usage.FetchUsage(ctx) if err != nil { + log.Debugf("usage.FetchUsage fail %s", err) + if usageChan != nil { + usageChan <- nil + } return }