data-usage: Fix the calculation of the next crawling round (#9096)

This commit fixes a simple typo miscalculated the waiting time
until the next round of data crawling to compute the data usage.
This commit is contained in:
Anis Elleuch 2020-03-06 11:34:12 -08:00 committed by GitHub
parent a1c7c9ea73
commit 75a0661213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,15 +74,15 @@ func timeToCrawl(ctx context.Context, objAPI ObjectLayer) time.Duration {
if dataUsageInfo.LastUpdate.IsZero() { if dataUsageInfo.LastUpdate.IsZero() {
return 1 * time.Second return 1 * time.Second
} }
waitDuration := dataUsageInfo.LastUpdate.Sub(UTCNow()) timeSinceLastUpdate := UTCNow().Sub(dataUsageInfo.LastUpdate)
if waitDuration > dataUsageCrawlInterval { if timeSinceLastUpdate > dataUsageCrawlInterval {
// Waited long enough start crawl in a 1 second // Waited long enough start crawl in a 1 second
return 1 * time.Second return 1 * time.Second
} }
// No crawling needed, ask the routine to wait until // No crawling needed, ask the routine to wait until
// the daily interval 12hrs - delta between last update // the daily interval 12hrs - delta between last update
// with current time. // with current time.
return dataUsageCrawlInterval - waitDuration return dataUsageCrawlInterval - timeSinceLastUpdate
} }
var dataUsageLockTimeout = lifecycleLockTimeout var dataUsageLockTimeout = lifecycleLockTimeout