Adding batch calculator utility and test cases for it.

This commit is contained in:
Renan DelValle 2019-09-14 10:20:23 -07:00
parent ace5da6bd3
commit b73954cd7c
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
2 changed files with 56 additions and 0 deletions

19
util.go
View file

@ -99,3 +99,22 @@ func validateAuroraURL(location string) (string, error) {
return u.String(), nil
}
func calculateCurrentBatch(updatingInstances int32, batchSizes []int32) int {
for i, size := range batchSizes {
updatingInstances -= size
if updatingInstances <= 0 {
return i
}
}
// Overflow batches
batchCount := len(batchSizes) - 1
lastBatchIndex := len(batchSizes) - 1
batchCount += int(updatingInstances / batchSizes[lastBatchIndex])
if updatingInstances%batchSizes[lastBatchIndex] != 0 {
batchCount++
}
return batchCount
}