-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: delete resources in batches of 10 (#784)
Closes #779 - Delete the resources in batches of 10 - Reduce the complexity of the code by not using `goroutines`. We are already trying to limit the strain on the API by deleting in batches of 10, therefor waiting the actions of multiple delete calls is enough "concurrency" for this use case.
- Loading branch information
Showing
4 changed files
with
72 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package util | ||
|
||
type ResourceState struct { | ||
IDOrName string | ||
Error error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package util | ||
|
||
func Batches[T any](all []T, size int) (batches [][]T) { | ||
for size < len(all) { | ||
all, batches = all[size:], append(batches, all[:size]) | ||
} | ||
return append(batches, all) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBatches(t *testing.T) { | ||
all := []int{1, 2, 3, 4, 5} | ||
batches := Batches(all, 2) | ||
|
||
assert.Len(t, batches, 3) | ||
assert.Equal(t, []int{1, 2}, batches[0]) | ||
assert.Equal(t, []int{3, 4}, batches[1]) | ||
assert.Equal(t, []int{5}, batches[2]) | ||
} |