feat: enable automatic re-indexing on schema version changes
2 files changed, 8 insertions(+), 14 deletions(-)
M internal/importer/main.go → internal/importer/main.go
@@ -303,10 +303,14 @@ Job.FinishedAt = imp.indexer.Meta.LastUpdated() var nextRun time.Time - if Job.FinishedAt.Before(time.Now().Add(-24 * time.Hour)) { + switch { + case Job.FinishedAt.Before(time.Now().Add(-24 * time.Hour)): imp.log.Info("indexing last ran more than 24 hours ago, scheduling immediate update") nextRun = time.Now() - } else { + case imp.indexer.Meta.IsSchemaOutdated(): + imp.log.Info("indexing schema version is out of date, scheduling immediate update") + nextRun = time.Now() + default: nextRun = nextUTCOccurrenceOfTime(imp.config.Importer.UpdateAt) } SetNextRun(nextRun)
M internal/index/index_meta.go → internal/index/index_meta.go
@@ -71,21 +71,11 @@ if err := json.Unmarshal(j, &meta.data); err != nil { return nil, errors.WithMessage(err, "index metadata is corrupt, try replacing the index") } - meta.checkSchemaVersion() - return &meta, nil } -func (i *Meta) checkSchemaVersion() { - if i.SchemaVersion < CurrentSchemaVersion { - i.log.Warn( - "Index schema version out of date, suggest re-indexing", - "schema_version", - i.SchemaVersion, - "latest_version", - CurrentSchemaVersion, - ) - } +func (i *Meta) IsSchemaOutdated() bool { + return i.SchemaVersion < CurrentSchemaVersion } func (i *Meta) Save() errors.E {