pollDeploymentStatus polls the deployment status until it's either running or errored, then prints the result
(ctx context.Context, client adminv1.AdminServiceClient, ch *cmdutil.Helper, deploymentID, project, branch, environment string)
| 84 | |
| 85 | // pollDeploymentStatus polls the deployment status until it's either running or errored, then prints the result |
| 86 | func pollDeploymentStatus(ctx context.Context, client adminv1.AdminServiceClient, ch *cmdutil.Helper, deploymentID, project, branch, environment string) error { |
| 87 | ticker := time.NewTicker(5 * time.Second) |
| 88 | defer ticker.Stop() |
| 89 | |
| 90 | for { |
| 91 | select { |
| 92 | case <-ctx.Done(): |
| 93 | return ctx.Err() |
| 94 | case <-ticker.C: |
| 95 | ch.Printf(".") |
| 96 | |
| 97 | // Fetch the deployment status using ListDeployments filtered by branch |
| 98 | resp, err := client.ListDeployments(ctx, &adminv1.ListDeploymentsRequest{ |
| 99 | Org: ch.Org, |
| 100 | Project: project, |
| 101 | Environment: environment, |
| 102 | Branch: branch, |
| 103 | }) |
| 104 | if err != nil { |
| 105 | return err |
| 106 | } |
| 107 | |
| 108 | // Find the deployment with matching ID - usually there's only one per branch |
| 109 | var deployment *adminv1.Deployment |
| 110 | for _, d := range resp.Deployments { |
| 111 | if d.Id == deploymentID { |
| 112 | deployment = d |
| 113 | break |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if deployment == nil { |
| 118 | return fmt.Errorf("deployment not found") |
| 119 | } |
| 120 | |
| 121 | // Check if deployment is in a terminal state and print result |
| 122 | switch deployment.Status { |
| 123 | case adminv1.DeploymentStatus_DEPLOYMENT_STATUS_RUNNING: |
| 124 | ch.PrintfSuccess("\n\nRuntime provisioned successfully!\n\n") |
| 125 | ch.Printf("Runtime Host: %s\n", deployment.RuntimeHost) |
| 126 | return nil |
| 127 | case adminv1.DeploymentStatus_DEPLOYMENT_STATUS_ERRORED: |
| 128 | ch.Printf("\n\n") |
| 129 | return fmt.Errorf("runtime provisioning failed: %s", deployment.StatusMessage) |
| 130 | } |
| 131 | // Continue polling for other statuses (PENDING, UPDATING, etc.) |
| 132 | } |
| 133 | } |
| 134 | } |
no test coverage detected