Skip to content

Commit f20bb3d

Browse files
committed
feat(go-client): add poll for processed
1 parent 9b75de7 commit f20bb3d

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

go/porcelain/deploy.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,16 @@ func (n *Netlify) WaitUntilDeployReady(ctx context.Context, d *models.Deploy) (*
403403
return n.waitForState(ctx, d, "prepared", "ready")
404404
}
405405

406-
// WaitUntilDeployLive blocks until the deploy is in the "ready" state. At this point, the deploy is ready to recieve traffic.
406+
// WaitUntilDeployLive blocks until the deploy is in the "ready" state. At this point, the deploy is ready to receive traffic to all of its URLs.
407407
func (n *Netlify) WaitUntilDeployLive(ctx context.Context, d *models.Deploy) (*models.Deploy, error) {
408408
return n.waitForState(ctx, d, "ready")
409409
}
410410

411+
// WaitUntilDeployProcessed blocks until the deploy is in the "processed" state. At this point, the deploy is ready to receive traffic via its permalink.
412+
func (n *Netlify) WaitUntilDeployProcessed(ctx context.Context, d *models.Deploy) (*models.Deploy, error) {
413+
return n.waitForState(ctx, d, "processed")
414+
}
415+
411416
func (n *Netlify) uploadFiles(ctx context.Context, d *models.Deploy, files *deployFiles, observer DeployObserver, t uploadType, timeout time.Duration, skipRetry bool) error {
412417
sharedErr := &uploadError{err: nil, mutex: &sync.Mutex{}}
413418
sem := make(chan int, n.uploadLimit)

go/porcelain/deploy_test.go

+49-2
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,64 @@ func TestWaitUntilDeployLive_Timeout(t *testing.T) {
132132
}))
133133
defer server.Close()
134134

135-
hu, _ := url.Parse(server.URL)
135+
hu, err := url.Parse(server.URL)
136+
require.NoError(t, err)
136137
tr := apiClient.NewWithClient(hu.Host, "/api/v1", []string{"http"}, http.DefaultClient)
137138
client := NewRetryable(tr, strfmt.Default, 1)
138139

139140
ctx := context.WithAuthInfo(gocontext.Background(), apiClient.BearerToken("token"))
140141
ctx, _ = gocontext.WithTimeout(ctx, 50*time.Millisecond)
141-
_, err := client.WaitUntilDeployLive(ctx, &models.Deploy{})
142+
_, err = client.WaitUntilDeployLive(ctx, &models.Deploy{})
142143
assert.Error(t, err)
143144
assert.Contains(t, err.Error(), "timed out")
144145
}
145146

147+
func TestWaitUntilDeployProcessed_Success(t *testing.T) {
148+
reqNum := 0
149+
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
150+
reqNum++
151+
rw.Header().Set("Content-Type", "application/json; charset=utf-8")
152+
153+
// validate the polling actually works
154+
if reqNum > 1 {
155+
rw.Write([]byte(`{ "state": "processed" }`))
156+
} else {
157+
rw.Write([]byte(`{ "state": "processing" }`))
158+
}
159+
}))
160+
defer server.Close()
161+
162+
hu, err := url.Parse(server.URL)
163+
require.NoError(t, err)
164+
tr := apiClient.NewWithClient(hu.Host, "/api/v1", []string{"http"}, http.DefaultClient)
165+
client := NewRetryable(tr, strfmt.Default, 1)
166+
167+
ctx := context.WithAuthInfo(gocontext.Background(), apiClient.BearerToken("token"))
168+
ctx, _ = gocontext.WithTimeout(ctx, 30*time.Second)
169+
d, err := client.WaitUntilDeployProcessed(ctx, &models.Deploy{})
170+
require.NoError(t, err)
171+
assert.Equal(t, "processed", d.State)
172+
}
173+
174+
func TestWaitUntilDeployProcessed_Timeout(t *testing.T) {
175+
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
176+
rw.Header().Set("Content-Type", "application/json; charset=utf-8")
177+
rw.Write([]byte(`{ "state": "processing" }`))
178+
}))
179+
defer server.Close()
180+
181+
hu, err := url.Parse(server.URL)
182+
require.NoError(t, err)
183+
tr := apiClient.NewWithClient(hu.Host, "/api/v1", []string{"http"}, http.DefaultClient)
184+
client := NewRetryable(tr, strfmt.Default, 1)
185+
186+
ctx := context.WithAuthInfo(gocontext.Background(), apiClient.BearerToken("token"))
187+
ctx, _ = gocontext.WithTimeout(ctx, 50*time.Millisecond)
188+
_, err = client.WaitUntilDeployProcessed(ctx, &models.Deploy{})
189+
require.Error(t, err)
190+
assert.Contains(t, err.Error(), "timed out")
191+
}
192+
146193
func TestWalk_IgnoreNodeModulesInRoot(t *testing.T) {
147194
dir, err := ioutil.TempDir("", "deploy")
148195
require.Nil(t, err)

swagger.yml

+1
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ paths:
935935
- preparing
936936
- prepared
937937
- processing
938+
- processed
938939
- ready
939940
- error
940941
- retrying

0 commit comments

Comments
 (0)