-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait.go
42 lines (37 loc) · 816 Bytes
/
wait.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package vuforia
import (
"context"
"errors"
"strings"
"time"
)
func WaitUntilProcessed(ctx context.Context, client Client, target string) error {
defaultInterval := 5 * time.Second
extendedInterval := 30 * time.Second
interval := defaultInterval
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(interval):
interval = defaultInterval
output, err := client.GetTarget(ctx, &GetTargetRequest{TargetId: target})
if err != nil {
var ae APIError
if errors.As(err, &ae) && strings.EqualFold(ae.ResultCode, "RequestQuotaReached") {
interval = extendedInterval
continue
}
return err
}
switch strings.ToLower(output.Status) {
case "failed", "success":
return nil
case "processing":
continue
default:
continue
}
}
}
}