logger: TTY logs support (live update)
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -3,8 +3,6 @@ package environment
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
cueflow "cuelang.org/go/tools/flow"
|
||||
@@ -184,10 +182,6 @@ func newPipelineRunner(computed *compiler.Value, s solver.Solver) cueflow.Runner
|
||||
ctx, span := tr.Start(ctx, fmt.Sprintf("compute: %s", t.Path().String()))
|
||||
defer span.End()
|
||||
|
||||
start := time.Now()
|
||||
lg.
|
||||
Info().
|
||||
Msg("computing")
|
||||
for _, dep := range t.Dependencies() {
|
||||
lg.
|
||||
Debug().
|
||||
@@ -203,19 +197,6 @@ func newPipelineRunner(computed *compiler.Value, s solver.Solver) cueflow.Runner
|
||||
attribute.String("error", err.Error()),
|
||||
))
|
||||
|
||||
// FIXME: this should use errdefs.IsCanceled(err)
|
||||
if strings.Contains(err.Error(), "context canceled") {
|
||||
lg.
|
||||
Error().
|
||||
Dur("duration", time.Since(start)).
|
||||
Msg("canceled")
|
||||
return err
|
||||
}
|
||||
lg.
|
||||
Error().
|
||||
Dur("duration", time.Since(start)).
|
||||
Err(err).
|
||||
Msg("failed")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -241,10 +222,6 @@ func newPipelineRunner(computed *compiler.Value, s solver.Solver) cueflow.Runner
|
||||
return err
|
||||
}
|
||||
|
||||
lg.
|
||||
Info().
|
||||
Dur("duration", time.Since(start)).
|
||||
Msg("completed")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
"github.com/docker/distribution/reference"
|
||||
@@ -27,6 +28,15 @@ import (
|
||||
"go.dagger.io/dagger/solver"
|
||||
)
|
||||
|
||||
type State string
|
||||
|
||||
const (
|
||||
StateComputing = State("computing")
|
||||
StateCanceled = State("canceled")
|
||||
StateFailed = State("failed")
|
||||
StateCompleted = State("completed")
|
||||
)
|
||||
|
||||
// An execution pipeline
|
||||
type Pipeline struct {
|
||||
code *compiler.Value
|
||||
@@ -146,6 +156,49 @@ func analyzeOp(fn func(*compiler.Value) error, op *compiler.Value) error {
|
||||
}
|
||||
|
||||
func (p *Pipeline) Run(ctx context.Context) error {
|
||||
lg := log.
|
||||
Ctx(ctx).
|
||||
With().
|
||||
Str("component", p.name).
|
||||
Logger()
|
||||
|
||||
start := time.Now()
|
||||
|
||||
lg.
|
||||
Info().
|
||||
Str("state", string(StateComputing)).
|
||||
Msg(string(StateComputing))
|
||||
|
||||
err := p.run(ctx)
|
||||
|
||||
if err != nil {
|
||||
// FIXME: this should use errdefs.IsCanceled(err)
|
||||
if strings.Contains(err.Error(), "context canceled") {
|
||||
lg.
|
||||
Error().
|
||||
Dur("duration", time.Since(start)).
|
||||
Str("state", string(StateCanceled)).
|
||||
Msg(string(StateCanceled))
|
||||
} else {
|
||||
lg.
|
||||
Error().
|
||||
Dur("duration", time.Since(start)).
|
||||
Err(err).
|
||||
Str("state", string(StateFailed)).
|
||||
Msg(string(StateFailed))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
lg.
|
||||
Info().
|
||||
Dur("duration", time.Since(start)).
|
||||
Str("state", string(StateCompleted)).
|
||||
Msg(string(StateCompleted))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Pipeline) run(ctx context.Context) error {
|
||||
ops, err := ops(p.code)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user