Skip to content

Commit

Permalink
Allow IGM to resume operation after interruption (#3928) (#514)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 29, 2020
1 parent 195a237 commit 4002624
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions google/compute_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package google

import (
"bytes"
"context"
"errors"
"fmt"
"log"
"time"

"google.golang.org/api/compute/v1"
Expand All @@ -11,6 +14,7 @@ import (
type ComputeOperationWaiter struct {
Service *compute.Service
Op *compute.Operation
Context context.Context
Project string
}

Expand Down Expand Up @@ -53,6 +57,15 @@ func (w *ComputeOperationWaiter) QueryOp() (interface{}, error) {
if w == nil || w.Op == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
if w.Context != nil {
select {
case <-w.Context.Done():
log.Println("[WARN] request has been cancelled early")
return w.Op, errors.New("unable to finish polling, context has been cancelled")
default:
// default must be here to keep the previous case from blocking
}
}
if w.Op.Zone != "" {
zone := GetResourceNameFromSelfLink(w.Op.Zone)
return w.Service.ZoneOperations.Get(w.Project, zone, w.Op.Name).Do()
Expand Down Expand Up @@ -88,6 +101,7 @@ func computeOperationWaitTime(config *Config, res interface{}, project, activity

w := &ComputeOperationWaiter{
Service: config.clientCompute,
Context: config.context,
Op: op,
Project: project,
}
Expand Down

0 comments on commit 4002624

Please sign in to comment.