terraform-provider-google/google/appengine_operation.go

46 lines
1.2 KiB
Go
Raw Normal View History

package google
import (
"fmt"
"regexp"
"google.golang.org/api/appengine/v1"
)
var (
2018-05-19 00:01:40 +00:00
appEngineOperationIdRegexp = regexp.MustCompile(fmt.Sprintf("apps/%s/operations/(.*)", ProjectRegex))
)
type AppEngineOperationWaiter struct {
Service *appengine.APIService
AppId string
2018-12-27 01:42:37 +00:00
CommonOperationWaiter
}
2018-12-27 01:42:37 +00:00
func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
2018-12-27 01:42:37 +00:00
matches := appEngineOperationIdRegexp.FindStringSubmatch(w.Op.Name)
if len(matches) != 2 {
return nil, fmt.Errorf("Expected %d results of parsing operation name, got %d from %s", 2, len(matches), w.Op.Name)
}
2018-12-27 01:42:37 +00:00
return w.Service.Apps.Operations.Get(w.AppId, matches[1]).Do()
}
func appEngineOperationWait(client *appengine.APIService, op *appengine.Operation, appId, activity string) error {
return appEngineOperationWaitTime(client, op, appId, activity, 4)
}
2018-12-27 01:42:37 +00:00
func appEngineOperationWaitTime(client *appengine.APIService, op *appengine.Operation, appId, activity string, timeoutMinutes int) error {
w := &AppEngineOperationWaiter{
Service: client,
AppId: appId,
}
2018-12-27 01:42:37 +00:00
if err := w.SetOp(op); err != nil {
return err
}
2018-12-27 01:42:37 +00:00
return OperationWait(w, activity, timeoutMinutes)
}