Skip to content

Commit

Permalink
Make it plugin wide
Browse files Browse the repository at this point in the history
Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Oct 22, 2024
1 parent e7039da commit 2cb0329
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 28 deletions.
29 changes: 1 addition & 28 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -55,39 +52,15 @@ 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)
}

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 {
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 2cb0329

Please sign in to comment.