Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print a message if a stage is taking more than 10 seconds #185

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package console
import (
"fmt"
"os/exec"
"time"

"github.com/hashicorp/go-multierror"
"github.com/mudler/yip/pkg/logger"
Expand Down Expand Up @@ -53,6 +54,8 @@ func (s StandardConsole) Run(cmd string, opts ...func(cmd *exec.Cmd)) (string, e
for _, o := range opts {
o(c)
}
displayProgress(s.logger, 10*time.Second, fmt.Sprintf("Still running command '%s'", cmd))
Itxaka marked this conversation as resolved.
Show resolved Hide resolved

out, err := c.CombinedOutput()
if err != nil {
return string(out), fmt.Errorf("failed to run %s: %v", cmd, err)
Expand All @@ -61,6 +64,25 @@ func (s StandardConsole) Run(cmd string, opts ...func(cmd *exec.Cmd)) (string, e
return string(out), err
}

func displayProgress(log logger.Interface, tick time.Duration, message string) {
ticker := time.NewTicker(tick)
done := make(chan bool)

go func() {
for {
select {
case <-done:
Itxaka marked this conversation as resolved.
Show resolved Hide resolved
ticker.Stop()
return
case <-ticker.C:
log.Info(message)
}
}
}()

return
}

func (s StandardConsole) Start(cmd *exec.Cmd, opts ...func(cmd *exec.Cmd)) error {
s.logger.Debugf("running command `%s`", cmd)
for _, o := range opts {
Expand Down
Loading