Skip to content

Commit

Permalink
simplify code and update docs/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
floreks committed May 15, 2024
1 parent d12aa6e commit a2d68c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions pkg/harness/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,22 @@ func (in *stackRunController) executables(ctx context.Context) []exec.Executable
}

func (in *stackRunController) toExecutable(ctx context.Context, step *gqlclient.RunStepFragment) exec.Executable {
// synchronize executable and underlying console writer with
// the controller to ensure that it does not exit before
// ensuring they have completed all work.
in.wg.Add(1)
consoleWriter := sink.NewConsoleLogWriter(

consoleWriter := sink.NewConsoleWriter(
ctx,
in.consoleClient,
append(
in.sinkOptions,
sink.WithID(step.ID),
sink.WithOnFinish(in.onLogWriterFinish),
sink.WithOnFinish(func() {
// Notify controller that all remaining work
// has been completed.
in.wg.Done()
}),
sink.WithStopChan(in.stopChan),
)...,
)
Expand All @@ -170,11 +178,6 @@ func (in *stackRunController) toExecutable(ctx context.Context, step *gqlclient.
)
}

func (in *stackRunController) onLogWriterFinish() {
klog.V(log.LogLevelTrace).InfoS("log writer finished")
in.wg.Done()
}

func (in *stackRunController) markStackRun(status gqlclient.StackStatus) error {
return in.consoleClient.UpdateStackRun(in.stackRunID, gqlclient.StackRunAttributes{
Status: status,
Expand Down
2 changes: 1 addition & 1 deletion pkg/harness/sink/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (in *ConsoleWriter) init() io.WriteCloser {
return in
}

func NewConsoleLogWriter(ctx context.Context, client console.Client, options ...Option) io.WriteCloser {
func NewConsoleWriter(ctx context.Context, client console.Client, options ...Option) io.WriteCloser {
result := &ConsoleWriter{
ctx: ctx,
buffer: helpers.NewBuffer(),
Expand Down

0 comments on commit a2d68c5

Please sign in to comment.