Skip to content

Commit 940c35b

Browse files
committed
make it a deploy option, not a client one
1 parent 43c1a41 commit 940c35b

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

go/porcelain/deploy.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
const (
3131
jsRuntime = "js"
3232
goRuntime = "go"
33+
34+
preProcessingTimeout = time.Minute * 5
3335
)
3436

3537
type uploadType int
@@ -62,10 +64,11 @@ type DeployOptions struct {
6264

6365
IsDraft bool
6466

65-
Title string
66-
Branch string
67-
CommitRef string
68-
UploadTimeout time.Duration
67+
Title string
68+
Branch string
69+
CommitRef string
70+
UploadTimeout time.Duration
71+
PreProcessTimeout time.Duration
6972

7073
Observer DeployObserver
7174

@@ -237,7 +240,7 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
237240

238241
if n.overCommitted(options.files) {
239242
var err error
240-
deploy, err = n.WaitUntilDeployReady(ctx, deploy)
243+
deploy, err = n.WaitUntilDeployReady(ctx, deploy, options.PreProcessTimeout)
241244
if err != nil {
242245
if options.Observer != nil {
243246
options.Observer.OnFailedDelta(deployFiles)
@@ -269,11 +272,15 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
269272
return deploy, nil
270273
}
271274

272-
func (n *Netlify) WaitUntilDeployReady(ctx context.Context, d *models.Deploy) (*models.Deploy, error) {
275+
func (n *Netlify) WaitUntilDeployReady(ctx context.Context, d *models.Deploy, timeout time.Duration) (*models.Deploy, error) {
273276
authInfo := context.GetAuthInfo(ctx)
274277
ticker := time.NewTicker(2 * time.Second)
275278
defer ticker.Stop()
276279

280+
if timeout <= 0 {
281+
timeout = preProcessingTimeout
282+
}
283+
277284
params := operations.NewGetSiteDeployParams().WithSiteID(d.SiteID).WithDeployID(d.ID)
278285
start := time.Now()
279286
for t := range ticker.C {
@@ -295,7 +302,7 @@ func (n *Netlify) WaitUntilDeployReady(ctx context.Context, d *models.Deploy) (*
295302
return nil, fmt.Errorf("Error: preprocessing deploy failed")
296303
}
297304

298-
if t.Sub(start) > n.preProcessingTimeout {
305+
if t.Sub(start) > timeout {
299306
return nil, fmt.Errorf("Error: preprocessing deploy timed out")
300307
}
301308
}

go/porcelain/netlify_client.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package porcelain
22

33
import (
4-
"time"
5-
64
"github.com/go-openapi/runtime"
75
httptransport "github.com/go-openapi/runtime/client"
86
"github.com/go-openapi/strfmt"
@@ -13,7 +11,6 @@ import (
1311
const DefaultSyncFileLimit = 7000
1412
const DefaultConcurrentUploadLimit = 10
1513
const DefaultRetryAttempts = 3
16-
const DefaultPreProcessingTimeout = time.Minute * 5
1714

1815
// Default netlify HTTP client.
1916
var Default = NewHTTPClient(nil)
@@ -44,19 +41,17 @@ func NewRetryable(transport runtime.ClientTransport, formats strfmt.Registry, at
4441
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Netlify {
4542
n := plumbing.New(transport, formats)
4643
return &Netlify{
47-
Netlify: n,
48-
syncFileLimit: DefaultSyncFileLimit,
49-
uploadLimit: DefaultConcurrentUploadLimit,
50-
preProcessingTimeout: DefaultPreProcessingTimeout,
44+
Netlify: n,
45+
syncFileLimit: DefaultSyncFileLimit,
46+
uploadLimit: DefaultConcurrentUploadLimit,
5147
}
5248
}
5349

5450
// Netlify is a client for netlify
5551
type Netlify struct {
5652
*plumbing.Netlify
57-
syncFileLimit int
58-
uploadLimit int
59-
preProcessingTimeout time.Duration
53+
syncFileLimit int
54+
uploadLimit int
6055
}
6156

6257
func (n *Netlify) SetSyncFileLimit(limit int) {
@@ -68,9 +63,3 @@ func (n *Netlify) SetConcurrentUploadLimit(limit int) {
6863
n.uploadLimit = limit
6964
}
7065
}
71-
72-
func (n *Netlify) SetPreProcessingTimeout(dur time.Duration) {
73-
if dur > 0 {
74-
n.preProcessingTimeout = dur
75-
}
76-
}

0 commit comments

Comments
 (0)