refactor: make importer.process a method
2 files changed, 6 insertions(+), 9 deletions(-)
M internal/importer/importer.go → internal/importer/importer.go
@@ -6,18 +6,15 @@ "sync" "alin.ovh/searchix/internal/index" "alin.ovh/searchix/internal/nix" - "alin.ovh/x/log" ) type Processor interface { Process(context.Context) (<-chan nix.Importable, <-chan error) } -func process( +func (imp *Importer) process( ctx context.Context, - indexer *index.WriteIndex, processor Processor, - logger *log.Logger, ) (bool, error) { wg := sync.WaitGroup{}@@ -25,7 +22,7 @@ wg.Add(1) objects, pErrs := processor.Process(ctx) wg.Add(1) - iErrs := indexer.Import(ctx, objects) + iErrs := imp.options.WriteIndex.Import(ctx, objects) var hadObjectErrors bool var criticalError error@@ -36,7 +33,7 @@ case err, running := <-iErrs: if !running { wg.Done() iErrs = nil - logger.Debug("ingest completed") + imp.options.Logger.Debug("ingest completed") continue }@@ -47,7 +44,7 @@ break } hadObjectErrors = true - logger.Warn("error ingesting object", "error", err) + imp.options.Logger.Warn("error ingesting object", "error", err) case err, running := <-pErrs: if !running { wg.Done()@@ -56,7 +53,7 @@ continue } hadObjectErrors = true - logger.Warn("error processing object", "error", err) + imp.options.Logger.Warn("error processing object", "error", err) } } }()
M internal/importer/main.go → internal/importer/main.go
@@ -183,7 +183,7 @@ if err != nil { return fault.Wrap(err, fmsg.Withf("failed to create processor")) } - hadWarnings, err := process(ctx, imp.options.WriteIndex, processor, logger) + hadWarnings, err := imp.process(ctx, processor) if err != nil { return fault.Wrap(err, fmsg.Withf("failed to process source")) }