2017-08-14 16:30:41 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
2019-01-25 21:03:43 +00:00
|
|
|
"fmt"
|
|
|
|
|
2017-08-14 16:30:41 +00:00
|
|
|
"google.golang.org/api/spanner/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SpannerInstanceOperationWaiter struct {
|
|
|
|
Service *spanner.Service
|
2018-12-27 01:42:37 +00:00
|
|
|
CommonOperationWaiter
|
2017-08-14 16:30:41 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func (w *SpannerInstanceOperationWaiter) QueryOp() (interface{}, error) {
|
2019-01-25 21:03:43 +00:00
|
|
|
if w == nil {
|
|
|
|
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
|
|
|
}
|
2018-12-27 01:42:37 +00:00
|
|
|
return w.Service.Projects.Instances.Operations.Get(w.Op.Name).Do()
|
2017-08-14 16:30:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-22 20:35:59 +00:00
|
|
|
func spannerOperationWaitTime(spanner *spanner.Service, op *spanner.Operation, _ string, activity string, timeoutMinutes int) error {
|
|
|
|
if op.Name == "" {
|
|
|
|
// This was a synchronous call - there is no operation to wait for.
|
|
|
|
return nil
|
|
|
|
}
|
2017-08-14 16:30:41 +00:00
|
|
|
w := &SpannerInstanceOperationWaiter{
|
2019-01-22 20:35:59 +00:00
|
|
|
Service: spanner,
|
2017-08-14 16:30:41 +00:00
|
|
|
}
|
2018-12-27 01:42:37 +00:00
|
|
|
if err := w.SetOp(op); err != nil {
|
|
|
|
return err
|
2017-08-14 16:30:41 +00:00
|
|
|
}
|
2018-12-27 01:42:37 +00:00
|
|
|
return OperationWait(w, activity, timeoutMinutes)
|
2017-08-14 16:30:41 +00:00
|
|
|
}
|