2018-05-10 22:01:22 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-05-14 05:49:26 +00:00
|
|
|
"regexp"
|
2018-05-10 22:01:22 +00:00
|
|
|
|
|
|
|
"google.golang.org/api/appengine/v1"
|
|
|
|
)
|
|
|
|
|
2018-05-14 05:49:26 +00:00
|
|
|
var (
|
2018-05-19 00:01:40 +00:00
|
|
|
appEngineOperationIdRegexp = regexp.MustCompile(fmt.Sprintf("apps/%s/operations/(.*)", ProjectRegex))
|
2018-05-14 05:49:26 +00:00
|
|
|
)
|
|
|
|
|
2018-05-10 22:01:22 +00:00
|
|
|
type AppEngineOperationWaiter struct {
|
|
|
|
Service *appengine.APIService
|
|
|
|
AppId string
|
2018-12-27 01:42:37 +00:00
|
|
|
CommonOperationWaiter
|
2018-05-10 22:01:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
func (w *AppEngineOperationWaiter) 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
|
|
|
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-05-10 22:01:22 +00:00
|
|
|
}
|
2018-12-27 01:42:37 +00:00
|
|
|
return w.Service.Apps.Operations.Get(w.AppId, matches[1]).Do()
|
2018-05-10 22:01:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2018-05-10 22:01:22 +00:00
|
|
|
w := &AppEngineOperationWaiter{
|
|
|
|
Service: client,
|
|
|
|
AppId: appId,
|
|
|
|
}
|
|
|
|
|
2018-12-27 01:42:37 +00:00
|
|
|
if err := w.SetOp(op); err != nil {
|
|
|
|
return err
|
2018-05-10 22:01:22 +00:00
|
|
|
}
|
2018-12-27 01:42:37 +00:00
|
|
|
return OperationWait(w, activity, timeoutMinutes)
|
2018-05-10 22:01:22 +00:00
|
|
|
}
|