From 2cb032994f6c8ddc0bb64a7b72e807590ac19c69 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Tue, 22 Oct 2024 09:24:23 +0200 Subject: [PATCH] Make it plugin wide Signed-off-by: Itxaka --- pkg/console/console.go | 29 +---------------------------- pkg/executor/default.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/pkg/console/console.go b/pkg/console/console.go index 338bb032..2a4cb33e 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -15,14 +15,11 @@ package console import ( - "context" "fmt" - "os/exec" - "time" - "github.com/hashicorp/go-multierror" "github.com/mudler/yip/pkg/logger" "github.com/sirupsen/logrus" + "os/exec" ) type StandardConsole struct { @@ -55,18 +52,8 @@ func (s StandardConsole) Run(cmd string, opts ...func(cmd *exec.Cmd)) (string, e for _, o := range opts { o(c) } - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - // Start the timer log - go displayProgress(ctx, s.logger, 10*time.Second, fmt.Sprintf("Still running command '%s'", cmd)) - - // Run the command out, err := c.CombinedOutput() - // Stop the timer log - cancel() - if err != nil { return string(out), fmt.Errorf("failed to run %s: %v", cmd, err) } @@ -74,20 +61,6 @@ func (s StandardConsole) Run(cmd string, opts ...func(cmd *exec.Cmd)) (string, e return string(out), err } -func displayProgress(ctx context.Context, log logger.Interface, tick time.Duration, message string) { - ticker := time.NewTicker(tick) - defer ticker.Stop() - - for { - select { - case <-ctx.Done(): - return - case <-ticker.C: - log.Info(message) - } - } -} - func (s StandardConsole) Start(cmd *exec.Cmd, opts ...func(cmd *exec.Cmd)) error { s.logger.Debugf("running command `%s`", cmd) for _, o := range opts { diff --git a/pkg/executor/default.go b/pkg/executor/default.go index 47f453d9..d5151234 100644 --- a/pkg/executor/default.go +++ b/pkg/executor/default.go @@ -21,6 +21,7 @@ import ( "github.com/sanity-io/litter" "os" "path/filepath" + "time" "github.com/hashicorp/go-multierror" "github.com/mudler/yip/pkg/logger" @@ -94,14 +95,31 @@ func (e *DefaultExecutor) applyStage(config schema.YipConfig, stageName string, e.logger.Debugf("Stage: %s", litter.Sdump(stage)) for _, p := range e.plugins { + ctx, cancel := context.WithCancel(context.Background()) + go stillAlive(ctx, e.logger, 10*time.Second, fmt.Sprintf("Still running stage '%s'", stageName)) if err := p(e.logger, stage, fs, console); err != nil { e.logger.Errorf("Error on file %s on stage %s: %s", config.Source, stage.Name, err) errs = multierror.Append(errs, err) } + cancel() } return errs } +func stillAlive(ctx context.Context, log logger.Interface, tick time.Duration, message string) { + ticker := time.NewTicker(tick) + defer ticker.Stop() + + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + log.Info(message) + } + } +} + func checkDuplicates(stages []schema.Stage) bool { stageNames := map[string]bool{} for _, st := range stages {