Skip to content

Commit 7601516

Browse files
author
smothiki
committed
feat(gitreceive): print status to avoid losing session
1 parent 8df2568 commit 7601516

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

pkg/gitreceive/build.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func build(
178178
return fmt.Errorf("creating builder pod (%s)", err)
179179
}
180180

181-
if err := waitForPod(kubeClient, newPod.Namespace, newPod.Name, conf.BuilderPodTickDuration(), conf.BuilderPodWaitDuration()); err != nil {
181+
if err := waitForPod(kubeClient, newPod.Namespace, newPod.Name, conf.SessionIdleInterval(), conf.BuilderPodTickDuration(), conf.BuilderPodWaitDuration()); err != nil {
182182
return fmt.Errorf("watching events for builder pod startup (%s)", err)
183183
}
184184

@@ -234,11 +234,13 @@ func build(
234234
}
235235

236236
log.Info("Build complete.")
237-
log.Info("Launching app.")
238-
log.Info("Launching...")
239237

240238
buildHook := createBuildHook(slugBuilderInfo, gitSha, conf.Username, appName, procType, usingDockerfile)
239+
quit := progress("...", conf.SessionIdleInterval())
241240
buildHookResp, err := publishRelease(conf, builderKey, buildHook)
241+
quit <- true
242+
<-quit
243+
log.Info("Launching App...")
242244
if err != nil {
243245
return fmt.Errorf("publishing release (%s)", err)
244246
}

pkg/gitreceive/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Config struct {
3232
BuilderPodWaitDurationMSec int `envconfig:"BUILDER_POD_WAIT_DURATION" default:"900000"` // 15 minutes
3333
ObjectStorageTickDurationMSec int `envconfing:"OBJECT_STORAGE_TICK_DURATION" default:"500"`
3434
ObjectStorageWaitDurationMSec int `envconfig:"OBJECT_STORAGE_WAIT_DURATION" default:"300000"` // 5 minutes
35+
SessionIdleIntervalMsec int `envconfig:"SESSION_IDLE_INTERVAL" default:"10000"` // 10 seconds
3536
SlugBuilderImage string `envconfig:"SLUGBUILDER_IMAGE_NAME" default:"quay.io/deisci/slugbuilder:v2-beta"`
3637
DockerBuilderImage string `envconfig:"DOCKERBUILDER_IMAGE_NAME" default:"quay.io/deisci/dockerbuilder:v2-beta"`
3738
SlugBuilderImagePullPolicy string `envconfig:"SLUG_BUILDER_IMAGE_PULL_POLICY" default:"Always"`
@@ -73,6 +74,11 @@ func (c Config) ObjectStorageWaitDuration() time.Duration {
7374
return time.Duration(time.Duration(c.ObjectStorageWaitDurationMSec) * time.Millisecond)
7475
}
7576

77+
// SessionIdleInterval returns the ticker interval to wait for status
78+
func (c Config) SessionIdleInterval() time.Duration {
79+
return time.Duration(time.Duration(c.SessionIdleIntervalMsec) * time.Millisecond)
80+
}
81+
7682
// CheckDurations checks if ticks for builder and object storage are not bigger
7783
// than the maximum duration. In case of this it will set the tick to the default.
7884
func (c *Config) CheckDurations() {

pkg/gitreceive/k8s_util.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func addEnvToPod(pod api.Pod, key, value string) {
171171
}
172172

173173
// waitForPod waits for a pod in state running or failed
174-
func waitForPod(c *client.Client, ns, podName string, interval, timeout time.Duration) error {
174+
func waitForPod(c *client.Client, ns, podName string, ticker, interval, timeout time.Duration) error {
175175
condition := func(pod *api.Pod) (bool, error) {
176176
if pod.Status.Phase == api.PodRunning {
177177
return true, nil
@@ -182,7 +182,11 @@ func waitForPod(c *client.Client, ns, podName string, interval, timeout time.Dur
182182
return false, nil
183183
}
184184

185-
return waitForPodCondition(c, ns, podName, condition, interval, timeout)
185+
quit := progress("...", ticker)
186+
err := waitForPodCondition(c, ns, podName, condition, interval, timeout)
187+
quit <- true
188+
<-quit
189+
return err
186190
}
187191

188192
// waitForPodEnd waits for a pod in state succeeded or failed
@@ -222,3 +226,21 @@ func waitForPodCondition(c *client.Client, ns, podName string, condition func(po
222226
return false, nil
223227
})
224228
}
229+
230+
func progress(msg string, interval time.Duration) chan bool {
231+
tick := time.Tick(interval)
232+
quit := make(chan bool)
233+
go func() {
234+
for {
235+
select {
236+
case <-quit:
237+
close(quit)
238+
return
239+
case <-tick:
240+
fmt.Println(msg)
241+
default:
242+
}
243+
}
244+
}()
245+
return quit
246+
}

0 commit comments

Comments
 (0)