@@ -33,7 +33,8 @@ const (
3333 jsRuntime = "js"
3434 goRuntime = "go"
3535
36- preProcessingTimeout = time .Minute * 5
36+ preProcessingTimeout = time .Minute * 5
37+ doneProcessingTimeout = time .Minute * 5
3738
3839 fileUpload uploadType = iota
3940 functionUpload
@@ -71,11 +72,12 @@ type DeployOptions struct {
7172
7273 IsDraft bool
7374
74- Title string
75- Branch string
76- CommitRef string
77- UploadTimeout time.Duration
78- PreProcessTimeout time.Duration
75+ Title string
76+ Branch string
77+ CommitRef string
78+ UploadTimeout time.Duration
79+ PreProcessTimeout time.Duration
80+ DoneProcessingTimeout time.Duration
7981
8082 Observer DeployObserver
8183
@@ -288,18 +290,14 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
288290 }
289291 }
290292
291- return deploy , nil
293+ return n . WaitForDeployComplete ( ctx , deploy , options . DoneProcessingTimeout )
292294}
293295
294- func (n * Netlify ) WaitUntilDeployReady (ctx context.Context , d * models.Deploy , timeout time.Duration ) (* models.Deploy , error ) {
296+ func (n * Netlify ) waitForState (ctx context.Context , d * models.Deploy , timeout time.Duration , states ... string ) (* models.Deploy , error ) {
295297 authInfo := context .GetAuthInfo (ctx )
296298 ticker := time .NewTicker (2 * time .Second )
297299 defer ticker .Stop ()
298300
299- if timeout <= 0 {
300- timeout = preProcessingTimeout
301- }
302-
303301 params := operations .NewGetSiteDeployParams ().WithSiteID (d .SiteID ).WithDeployID (d .ID )
304302 start := time .Now ()
305303 for t := range ticker .C {
@@ -313,22 +311,39 @@ func (n *Netlify) WaitUntilDeployReady(ctx context.Context, d *models.Deploy, ti
313311 "state" : resp .Payload .State ,
314312 }).Debug ("Waiting until deploy ready" )
315313
316- if resp .Payload .State == "prepared" || resp .Payload .State == "ready" {
317- return resp .Payload , nil
314+ for _ , state := range states {
315+ if resp .Payload .State == state {
316+ return resp .Payload , nil
317+ }
318318 }
319319
320320 if resp .Payload .State == "error" {
321- return nil , fmt .Errorf ("Error: preprocessing deploy failed" )
321+ return nil , fmt .Errorf ("Error: entered errors state while waiting to enter states: %s" , strings . Join ( states , "," ) )
322322 }
323323
324324 if t .Sub (start ) > timeout {
325- return nil , fmt .Errorf ("Error: preprocessing deploy timed out" )
325+ return nil , fmt .Errorf ("Error: deploy timed out while waiting to enter states: %s" , strings . Join ( states , "," ) )
326326 }
327327 }
328328
329329 return d , nil
330330}
331331
332+ func (n * Netlify ) WaitUntilDeployReady (ctx context.Context , d * models.Deploy , timeout time.Duration ) (* models.Deploy , error ) {
333+ if timeout <= 0 {
334+ timeout = preProcessingTimeout
335+ }
336+
337+ return n .waitForState (ctx , d , timeout , "prepared" , "ready" )
338+ }
339+
340+ func (n * Netlify ) WaitForDeployComplete (ctx context.Context , d * models.Deploy , timeout time.Duration ) (* models.Deploy , error ) {
341+ if timeout <= 0 {
342+ timeout = doneProcessingTimeout
343+ }
344+ return n .waitForState (ctx , d , timeout , "ready" )
345+ }
346+
332347func (n * Netlify ) uploadFiles (ctx context.Context , d * models.Deploy , files * deployFiles , observer DeployObserver , t uploadType , timeout time.Duration ) error {
333348 sharedErr := & uploadError {err : nil , mutex : & sync.Mutex {}}
334349 sem := make (chan int , n .uploadLimit )
0 commit comments