feat: periodically update progress during build (#537)

Some feedback from the user interviews indicated that people sometimes
get confused by how long it takes to  build a function the first time
and are tempted to kill the process. This change updates the progress
message every five seconds for twenty seconds, and if a build takes longer
than that the message remains "Still building".

Not sure if this is really needed, but it was a fun and easy fix.

Signed-off-by: Lance Ball <lball@redhat.com>
This commit is contained in:
Lance Ball 2021-09-19 19:02:34 -04:00 committed by GitHub
parent ad4607bd50
commit 01689e7c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
"runtime"
"sort"
"sync"
"time"
"gopkg.in/yaml.v2"
)
@ -508,8 +509,34 @@ func (c *Client) Create(cfg Function) (err error) {
// not contain a populated Image.
func (c *Client) Build(ctx context.Context, path string) (err error) {
c.progressListener.Increment("Building function image")
m := []string{
"Still building",
"Don't give up",
"This is taking a while",
"Still building"}
ticker := time.NewTicker(5 * time.Second)
quit := make(chan struct{})
go func() {
for {
select {
case <-ticker.C:
if len(m) == 0 {
close(quit)
break
}
c.progressListener.Increment(m[0])
m = m[1:] // remove 0th element
case <-quit:
ticker.Stop()
return
}
}
}()
go func() {
<-ctx.Done()
close(quit)
c.progressListener.Stopping()
}()