Skip to content

Commit 92bf599

Browse files
committed
Fix ThrottlingException
1 parent 2a1db74 commit 92bf599

File tree

2 files changed

+71
-34
lines changed

2 files changed

+71
-34
lines changed

cmd/deploy/deploy.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"sync"
7+
"time"
78

89
"github.com/aws/aws-sdk-go/aws/session"
910
"github.com/daaru00/aws-ssm-document-cli/internal/aws"
@@ -84,28 +85,47 @@ func Action(c *cli.Context) error {
8485
return err
8586
}
8687

87-
// Setup wait group for async jobs
88-
var waitGroup sync.WaitGroup
89-
9088
// Setup errors channel
9189
errs := make(chan error, len(*documents))
9290

93-
// Loop over found document
94-
for _, cy := range *documents {
91+
// Setup max parallels
92+
allDocuments := *documents
93+
parallel := 10
9594

96-
// Execute parallel deploy
97-
waitGroup.Add(1)
98-
go func(document *document.Document) {
99-
defer waitGroup.Done()
95+
// Start parallel deploy
96+
for start := 0; start < len(allDocuments); start += parallel {
97+
// Update chunk start and end
98+
end := start + parallel
99+
if end > len(allDocuments) {
100+
end = len(allDocuments)
101+
}
100102

101-
err := deploySingleDocument(ses, region, accountID, document)
103+
// Split array chunk
104+
chunk := allDocuments[start:end]
102105

103-
errs <- err
104-
}(cy)
105-
}
106+
// Setup wait group for async jobs
107+
var waitGroup sync.WaitGroup
108+
109+
// Loop over found document
110+
for _, cy := range chunk {
111+
112+
// Execute parallel deploy
113+
waitGroup.Add(1)
114+
go func(document *document.Document) {
115+
defer waitGroup.Done()
106116

107-
// Wait until all remove ends
108-
waitGroup.Wait()
117+
err := deploySingleDocument(ses, region, accountID, document)
118+
119+
errs <- err
120+
}(cy)
121+
}
122+
123+
// Wait until all remove ends
124+
waitGroup.Wait()
125+
126+
// Do dummy wait
127+
time.Sleep(2000 * time.Microsecond)
128+
}
109129

110130
// Close errors channel
111131
close(errs)

cmd/remove/remove.go

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"sync"
7+
"time"
78

89
"github.com/AlecAivazis/survey/v2"
910
"github.com/aws/aws-sdk-go/aws/session"
@@ -86,31 +87,47 @@ func Action(c *cli.Context) error {
8687
return err
8788
}
8889

89-
// Setup wait group for async jobs
90-
var waitGroup sync.WaitGroup
91-
92-
// Setup deploy chan error
90+
// Setup errors channel
9391
errs := make(chan error, len(*documents))
9492

95-
// Loop over found documents
96-
for _, cy := range *documents {
93+
// Setup max parallels
94+
allDocuments := *documents
95+
parallel := 10
9796

98-
// Execute parallel deploy
99-
waitGroup.Add(1)
100-
go func(document *document.Document) {
101-
defer waitGroup.Done()
102-
var err error
97+
// Start parallel deploy
98+
for start := 0; start < len(allDocuments); start += parallel {
99+
// Update chunk start and end
100+
end := start + parallel
101+
if end > len(allDocuments) {
102+
end = len(allDocuments)
103+
}
103104

104-
if err == nil {
105-
err = removeSingleDocument(ses, document, region)
106-
}
105+
// Split array chunk
106+
chunk := allDocuments[start:end]
107107

108-
errs <- err
109-
}(cy)
110-
}
108+
// Setup wait group for async jobs
109+
var waitGroup sync.WaitGroup
110+
111+
// Loop over found document
112+
for _, cy := range chunk {
113+
114+
// Execute parallel deploy
115+
waitGroup.Add(1)
116+
go func(document *document.Document) {
117+
defer waitGroup.Done()
111118

112-
// Wait until all remove ends
113-
waitGroup.Wait()
119+
err := removeSingleDocument(ses, document, region)
120+
121+
errs <- err
122+
}(cy)
123+
}
124+
125+
// Wait until all remove ends
126+
waitGroup.Wait()
127+
128+
// Do dummy wait
129+
time.Sleep(2000 * time.Microsecond)
130+
}
114131

115132
// Close errors channel
116133
close(errs)

0 commit comments

Comments
 (0)