Skip to content

Commit

Permalink
return an error from Finish.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Jul 31, 2023
1 parent a4d1651 commit 822668a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ func run(state overseer.State) {
}

// Wait for all workers to finish.
e.Finish(ctx, logFatal)
if err = e.Finish(ctx); err != nil {
logFatal(err, "engine failed to finish execution")
}

metrics := e.GetMetrics()
// Print results.
Expand Down
9 changes: 4 additions & 5 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,10 @@ func Start(ctx context.Context, options ...EngineOption) (*Engine, error) {
// Finish waits for running sources to complete and workers to finish scanning
// chunks before closing their respective channels. Once Finish is called, no
// more sources may be scanned by the engine.
func (e *Engine) Finish(ctx context.Context, logFunc func(error, string, ...any)) {
func (e *Engine) Finish(ctx context.Context) error {
defer common.RecoverWithExit(ctx)
// Wait for the sources to finish putting chunks onto the chunks channel.
sourceErr := e.sourcesWg.Wait()
if sourceErr != nil {
logFunc(sourceErr, "error occurred while collecting chunks")
}
err := e.sourcesWg.Wait()

close(e.chunks) // Source workers are done.

Expand All @@ -398,6 +395,8 @@ func (e *Engine) Finish(ctx context.Context, logFunc func(error, string, ...any)

close(e.results) // Detector workers are done, close the results channel and call it a day.
e.WgNotifier.Wait() // Wait for the notifier workers to finish notifying results.

return err
}

func (e *Engine) ChunksChan() chan *sources.Chunk {
Expand Down

0 comments on commit 822668a

Please sign in to comment.