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

Pipeline: propagate ActionContext to Listener when logging custom messages #58

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions pipeline/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ func (ac actContext) Snapshot() map[string]interface{} {
}

func (p *exec) newCtx(a Action) *actContext {
return &actContext{
ctx := &actContext{
c: a,
d: p.gd,
e: p,
f: b,
t: p.t,
l: &listenerLoggerAdapter{l: p.l},
}
ctx.l.c = ctx
return ctx
}

func (p *exec) Execute(act Action) (err error) {
Expand All @@ -71,16 +73,17 @@ func (p *exec) Execute(act Action) (err error) {

type noopListener struct{}

func (n *noopListener) OnBefore(ActionContext) {}
func (n *noopListener) OnAfter(ActionContext, error) {}
func (n *noopListener) OnLog(...interface{}) {}
func (n *noopListener) OnBefore(ActionContext) {}
func (n *noopListener) OnAfter(ActionContext, error) {}
func (n *noopListener) OnLog(ActionContext, ...interface{}) {}

type listenerLoggerAdapter struct {
c ActionContext
l Listener
}

func (n *listenerLoggerAdapter) Log(v ...interface{}) {
n.l.OnLog(v)
n.l.OnLog(n.c, v)
}

type Opt func(*exec)
Expand Down
2 changes: 1 addition & 1 deletion pipeline/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Listener interface {
// Any error returned by invoking Do() method is returned as last parameter.
OnAfter(ctx ActionContext, err error)
// OnLog is called whenever action invokes Log method on Logger instance
OnLog(v ...interface{})
OnLog(ctx ActionContext, v ...interface{})
}

// ActionContext is created by Executor implementation for sole purpose of invoking Action's Do function.
Expand Down
Loading