Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check project health on bootstrap #2109

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion internal/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ func Run(ctx context.Context, templateUrl string, fsys afero.Fs, options ...func
if err := utils.WriteFile(utils.ProjectRefPath, []byte(flags.ProjectRef), fsys); err != nil {
return err
}
// 5. Push migrations
// 5. Wait for project healthy
policy.Reset()
if err := backoff.RetryNotify(func() error {
fmt.Fprintln(os.Stderr, "Checking project health...")
return checkProjectHealth(ctx)
}, policy, newErrorCallback()); err != nil {
return err
}
// 6. Push migrations
config := flags.NewDbConfigWithPassword(flags.ProjectRef)
if err := writeDotEnv(keys, config, fsys); err != nil {
fmt.Fprintln(os.Stderr, "Failed to create .env file:", err)
Expand Down Expand Up @@ -137,6 +145,27 @@ func suggestAppStart(cwd string) string {
return suggestion
}

func checkProjectHealth(ctx context.Context) error {
params := api.CheckServiceHealthParams{
Services: []api.CheckServiceHealthParamsServices{
api.CheckServiceHealthParamsServicesDb,
},
}
resp, err := utils.GetSupabase().CheckServiceHealthWithResponse(ctx, flags.ProjectRef, &params)
if err != nil {
return err
}
if resp.JSON200 == nil {
return errors.Errorf("Error status %d: %s", resp.StatusCode(), resp.Body)
}
for _, service := range *resp.JSON200 {
if !service.Healthy {
return errors.Errorf("Service not healthy: %s (%s)", service.Name, service.Status)
}
}
return nil
}

const maxRetries = 8

func newBackoffPolicy(ctx context.Context) backoff.BackOffContext {
Expand Down