internal/importer/importer.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | package importer import ( "context" "alin.ovh/searchix/internal/config" "alin.ovh/searchix/internal/nix" "alin.ovh/searchix/internal/storage" ) type Processor interface { Process(context.Context) (<-chan nix.Importable, <-chan error) } type ( ImportSource func(context.Context) (<-chan nix.Importable, <-chan error) ImportDestination func(context.Context, <-chan nix.Importable) <-chan error ) func (imp *Importer) indexSource( ctx context.Context, source *config.Source, ) (bool, error) { writer := imp.options.WriteIndex var exporter func(context.Context) (<-chan nix.Importable, <-chan error) switch source.Importer { case config.Packages: exporter = storage.MakeSourceExporter[nix.Package]( imp.options.Storage, source, writer.GetBatchSize(), ) case config.Options: exporter = storage.MakeSourceExporter[nix.Option]( imp.options.Storage, source, writer.GetBatchSize(), ) } return pipe( ctx, imp.options.Logger, exporter, func(ctx context.Context, objects <-chan nix.Importable) <-chan error { return writer.Import(ctx, objects) }, ) } |