Skip to content

Commit a0453ca

Browse files
changed pooling parameters transfer for blue green strategy
1 parent 921a960 commit a0453ca

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

operation/push.go

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"io"
88
"os"
9-
"strconv"
109
"time"
1110

1211
"gopkg.in/yaml.v3"
@@ -26,17 +25,17 @@ const (
2625
const (
2726
AppDeployedRunningCheckIntervalSecondsDefault = 5
2827
AppDeployedRunningTimeoutMinutesDefault = 5
29-
EnvironmentVariablesConvertBaseDecimal = 10
30-
EnvironmentVariablesConvertBitsSize = 32
3128
)
3229

3330
// AppPushOperation can be used to push buildpack apps
3431
type AppPushOperation struct {
35-
orgName string
36-
spaceName string
37-
client *client.Client
38-
strategy StrategyMode
39-
stopped bool
32+
orgName string
33+
spaceName string
34+
client *client.Client
35+
strategy StrategyMode
36+
stopped bool
37+
timeout uint
38+
checkInterval uint
4039
}
4140

4241
// NewAppPushOperation creates a new AppPushOperation
@@ -59,6 +58,12 @@ func (p *AppPushOperation) WithStrategy(s StrategyMode) {
5958
}
6059
}
6160

61+
func (p *AppPushOperation) WithBlueGreenStrategy(timeout uint, checkInterval uint) {
62+
p.strategy = StrategyBlueGreen
63+
p.timeout = timeout
64+
p.checkInterval = checkInterval
65+
}
66+
6267
func (p *AppPushOperation) WithNoStart(stopped bool) {
6368
p.stopped = stopped
6469
}
@@ -146,7 +151,7 @@ func (p *AppPushOperation) pushBlueGreenApp(ctx context.Context, space *resource
146151
}
147152

148153
if newApp.State == "STARTED" {
149-
pollOptions := p.getAppDeployedRunningPollingOptions(ctx)
154+
pollOptions := p.getAppDeployedRunningPollingOptions()
150155
healthCheckErr := p.waitForAppHealthy(ctx, newApp, pollOptions)
151156
// If health check fails, delete new app and change back original app name
152157
if healthCheckErr != nil {
@@ -171,38 +176,19 @@ func (p *AppPushOperation) pushBlueGreenApp(ctx context.Context, space *resource
171176
return newApp, fmt.Errorf("failed to verify application start: %w", pushError)
172177
}
173178

174-
func (p *AppPushOperation) getAppDeployedRunningPollingOptions(ctx context.Context) *client.PollingOptions {
175-
rawTimeout := ctx.Value("app_deployed_running_timeout")
176-
processedTimeout := uint(AppDeployedRunningTimeoutMinutesDefault)
179+
func (p *AppPushOperation) getAppDeployedRunningPollingOptions() *client.PollingOptions {
177180

178-
rawCheckInterval := ctx.Value("app_deployed_running_check_interval")
179-
processedCheckInterval := uint(AppDeployedRunningCheckIntervalSecondsDefault)
180-
181-
if rawTimeout != nil {
182-
t, ok := rawTimeout.(uint)
183-
if ok == true {
184-
processedTimeout = t
185-
}
186-
} else if envTimeout := os.Getenv("CF_APP_DEPLOYED_RUNNING_TIMEOUT"); envTimeout != "" {
187-
if t, err := strconv.ParseUint(envTimeout, EnvironmentVariablesConvertBaseDecimal, EnvironmentVariablesConvertBitsSize); err == nil {
188-
processedTimeout = uint(t)
189-
}
181+
if p.timeout == 0 {
182+
p.timeout = uint(AppDeployedRunningTimeoutMinutesDefault)
190183
}
191184

192-
if rawCheckInterval != nil {
193-
ci, ok := rawCheckInterval.(uint)
194-
if ok {
195-
processedCheckInterval = ci
196-
}
197-
} else if envInterval := os.Getenv("CF_APP_DEPLOYED_RUNNING_CHECK_INTERVAL"); envInterval != "" {
198-
if ci, err := strconv.ParseUint(envInterval, EnvironmentVariablesConvertBaseDecimal, EnvironmentVariablesConvertBitsSize); err == nil {
199-
processedCheckInterval = uint(ci)
200-
}
185+
if p.checkInterval == 0 {
186+
p.checkInterval = uint(AppDeployedRunningCheckIntervalSecondsDefault)
201187
}
202188

203189
pollOptions := client.NewPollingOptions()
204-
pollOptions.Timeout = time.Duration(processedTimeout) * time.Minute
205-
pollOptions.CheckInterval = time.Duration(processedCheckInterval) * time.Second
190+
pollOptions.Timeout = time.Duration(p.timeout) * time.Minute
191+
pollOptions.CheckInterval = time.Duration(p.checkInterval) * time.Second
206192
return pollOptions
207193
}
208194

0 commit comments

Comments
 (0)