feat: add --fetch action to populate data/sources
1 file changed, 9 insertions(+), 4 deletions(-)
changed files
M internal/importer/main.go → internal/importer/main.go
@@ -62,6 +62,7 @@ func (imp *Importer) createSourceImporter( parent context.Context, meta *index.Meta, forceUpdate bool, + fetchOnly bool, ) func(*config.Source) error { return func(source *config.Source) error { logger := imp.options.Logger.With("name", source.Key)@@ -105,16 +106,18 @@ } logger.Info( "importer fetch succeeded", "previous", - previousUpdate, + previousUpdate.Format(time.DateTime), "current", sourceMeta.Updated.Format(time.DateTime), "is_updated", sourceMeta.Updated.After(previousUpdate), "update_force", forceUpdate, + "fetch_only", + fetchOnly, ) - if sourceMeta.Updated.After(previousUpdate) || forceUpdate { + if !fetchOnly && (!sourceMeta.Updated.After(previousUpdate) || forceUpdate) { var pdb *programs.DB if source.Programs.Enable {@@ -191,6 +194,7 @@ func (imp *Importer) Start( ctx context.Context, forceUpdate bool, + fetchOnly bool, onlyUpdateSources *[]string, ) error { if len(imp.config.Importer.Sources) == 0 {@@ -210,7 +214,7 @@ forceUpdate = forceUpdate || (onlyUpdateSources != nil && len(*onlyUpdateSources) > 0) meta := imp.options.WriteIndex.Meta - importSource := imp.createSourceImporter(importCtx, meta, forceUpdate) + importSource := imp.createSourceImporter(importCtx, meta, forceUpdate, fetchOnly) for name, source := range imp.config.Importer.Sources { if onlyUpdateSources != nil && len(*onlyUpdateSources) > 0 { if !slices.Contains(*onlyUpdateSources, name) {@@ -267,6 +271,7 @@ imp.options.Logger.Info("adding new sources", "sources", newSources) err := imp.Start( ctx, false, + false, &newSources, ) if err != nil {@@ -337,7 +342,7 @@ }, monitorConfig) MarkIndexingStarted() ctx, cancel := context.WithTimeout(parentCtx, imp.config.Importer.Timeout.Duration) - err = imp.Start(ctx, false, nil) + err = imp.Start(ctx, false, false, nil) cancel() if err != nil {