Skip to content

Commit

Permalink
fix: check project health on bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Apr 1, 2024
1 parent 75b6ab9 commit 495ef5d
Showing 1 changed file with 30 additions and 1 deletion.
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

0 comments on commit 495ef5d

Please sign in to comment.