示例#1
0
func waitForBuild(client *client.Client, appName, buildID string) (string, error) {
	timeout := time.After(30 * time.Minute)
	tick := time.Tick(10 * time.Second)

	fmt.Print("🐮  Waiting for Convox build to finish... ")

	for {
		select {
		case <-tick:
			build, err := client.GetBuild(appName, buildID)
			if err != nil {
				fmt.Println("✘")
				return "", err
			}

			switch build.Status {
			case "complete":
				fmt.Println("✔")
				return build.Release, nil
			case "error", "failed":
				fmt.Println("✘")
				return "", fmt.Errorf("%s build failed: %s", appName, build.Status)
			default:
				if Verbose {
					fmt.Print(".")
				}
			}
		case <-timeout:
			fmt.Println("✘")
			return "", fmt.Errorf("%s build failed: timeout", appName)
		}
	}
}
示例#2
0
func finishBuild(client *client.Client, appName string, build *client.Build) (string, error) {

	if build.Id == "" {
		return "", fmt.Errorf("unable to fetch build id")
	}

	if Verbose {
		reader, writer := io.Pipe()
		go io.Copy(os.Stdout, reader)
		if err := client.StreamBuildLogs(appName, build.Id, writer); err != nil {
			return "", err
		}
	}

	return waitForBuild(client, appName, build.Id)
}