Skip to content

Commit

Permalink
Print a message if a stage is taking more than 10 seconds (#185)
Browse files Browse the repository at this point in the history
* Print a message if a command is taking more than 10 seconds

Signed-off-by: Itxaka <[email protected]>

* do not return a chan

Signed-off-by: Itxaka <[email protected]>

* Fix the timer display

Signed-off-by: Itxaka <[email protected]>

* Make it plugin wide

Signed-off-by: Itxaka <[email protected]>

---------

Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka authored Oct 22, 2024
1 parent 5338e89 commit cfe101e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ package console

import (
"fmt"
"os/exec"

"github.com/hashicorp/go-multierror"
"github.com/mudler/yip/pkg/logger"
"github.com/sirupsen/logrus"
"os/exec"
)

type StandardConsole struct {
Expand Down Expand Up @@ -54,6 +53,7 @@ func (s StandardConsole) Run(cmd string, opts ...func(cmd *exec.Cmd)) (string, e
o(c)
}
out, err := c.CombinedOutput()

if err != nil {
return string(out), fmt.Errorf("failed to run %s: %v", cmd, err)
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/executor/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cfe101e

Please sign in to comment.