Skip to content

Commit b685a4b

Browse files
committed
poll for successful direct access
1 parent 9433fc6 commit b685a4b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

internal/pkg/rpa/main.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ func (a *App) pollImageAccessEnabled(groupID int, stateDesired bool) {
293293
}
294294

295295
func (a *App) directAccess(t Task) error {
296+
297+
pollDelay := 10 // seconds
298+
pollCount := 0 // iteration counter
299+
pollMax := 30 // max times to poll before breaking the poll loop
300+
296301
operationName := "Disabling"
297302
operation := "disable_direct_access"
298303
if t.Enable == true {
@@ -304,10 +309,16 @@ func (a *App) directAccess(t Task) error {
304309
t.GroupUID, t.ClusterUID, t.CopyUID, operation)
305310
if !a.Config.CheckMode {
306311
body, statusCode := a.apiRequest("PUT", endpoint, nil)
307-
if statusCode != 204 {
312+
for statusCode != 204 {
308313
log.Debugf("Expected status code '204' and received: %d\n", statusCode)
309-
log.Warnf("Error enabling Direct Access for Group %s Copy %s\n", t.GroupName, t.CopyName)
310-
return errors.New(string(body))
314+
time.Sleep(time.Duration(pollDelay) * time.Second)
315+
body, statusCode = a.apiRequest("PUT", endpoint, nil)
316+
if pollCount > pollMax {
317+
fmt.Println("Maximum poll count reached while waiting for direct access")
318+
log.Warnf("Error %s Direct Access for Group %s Copy %s\n", operationName, t.GroupName, t.CopyName)
319+
return errors.New(string(body))
320+
}
321+
pollCount++
311322
}
312323
}
313324
fmt.Printf("%s Direct Access for Group %s Copy %s\n", operationName, t.GroupName, t.CopyName)

0 commit comments

Comments
 (0)