Skip to content

Commit 0b6cc33

Browse files
committed
chore: limit document download requests in cli
1 parent 2e56784 commit 0b6cc33

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

comdirect/cmd/document.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99
"os"
1010
"strings"
11+
"time"
1112
)
1213

1314
var (
@@ -61,11 +62,15 @@ func document(cmd *cobra.Command, args []string) {
6162
func download(client *comdirect.Client, documents *comdirect.Documents) {
6263
ctx, cancel := contextWithTimeout()
6364
defer cancel()
64-
for _, d := range documents.Values {
65+
for i, d := range documents.Values {
6566
err := client.DownloadDocument(ctx, &d, folderFlag)
6667
if err != nil {
6768
log.Fatal("failed to download document: ", err)
6869
}
70+
// TODO: think about a better solution to limit download requests to 10/sec
71+
if i % 10 == 0 && i != 0{
72+
time.Sleep(900 * time.Millisecond)
73+
}
6974
fmt.Printf("Download complete for document with ID %s\n", d.DocumentID)
7075
}
7176
}

0 commit comments

Comments
 (0)