MCPcopy Create free account
hub / github.com/algolia/cli / CreateApplicationWithRetry

Function CreateApplicationWithRetry

pkg/cmd/shared/apputil/create.go:22–67  ·  view source on GitHub ↗

CreateApplicationWithRetry creates an application, retrying with a different region if the selected one has no available cluster. The optional tracker (nil-safe) records which step the flow is in, so the telemetry of the calling flow can tell where the user stopped.

(
	io *iostreams.IOStreams,
	client *dashboard.Client,
	accessToken string,
	region string,
	appName string,
	tracker *telemetry.FlowTracker,
)

Source from the content-addressed store, hash-verified

20// The optional tracker (nil-safe) records which step the flow is in, so the
21// telemetry of the calling flow can tell where the user stopped.
22func CreateApplicationWithRetry(
23 io *iostreams.IOStreams,
24 client *dashboard.Client,
25 accessToken string,
26 region string,
27 appName string,
28 tracker *telemetry.FlowTracker,
29) (*dashboard.Application, string, error) {
30 cs := io.ColorScheme()
31
32 for {
33 if region == "" {
34 tracker.SetStep(telemetry.StepRegion)
35 var err error
36 region, err = PromptRegion(io, client, accessToken)
37 if err != nil {
38 return nil, "", err
39 }
40 }
41
42 tracker.SetStep(telemetry.StepAPICall)
43 io.StartProgressIndicatorWithLabel("Creating application")
44 app, err := client.CreateApplication(accessToken, region, appName)
45 io.StopProgressIndicator()
46
47 if err == nil {
48 fmt.Fprintf(io.Out, "%s Application %s created in region %q\n",
49 cs.SuccessIcon(), cs.Bold(app.ID), region)
50 return app, region, nil
51 }
52
53 var clusterErr *dashboard.ErrClusterUnavailable
54 if errors.As(err, &clusterErr) {
55 fmt.Fprintf(io.Out, "%s No cluster available in region %q. Please select another region.\n",
56 cs.WarningIcon(), region)
57 region = ""
58
59 if !io.CanPrompt() {
60 return nil, "", fmt.Errorf("no cluster available in region %q — try a different --region", clusterErr.Region)
61 }
62 continue
63 }
64
65 return nil, "", fmt.Errorf("application creation failed: %w", err)
66 }
67}
68
69// PromptRegion fetches regions from the API and prompts the user to select one.
70func PromptRegion(

Callers 1

Calls 11

PromptRegionFunction · 0.85
ColorSchemeMethod · 0.80
SetStepMethod · 0.80
CreateApplicationMethod · 0.80
StopProgressIndicatorMethod · 0.80
SuccessIconMethod · 0.80
BoldMethod · 0.80
WarningIconMethod · 0.80
CanPromptMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected