From 200857159766d3c6c5831450048348444c5666f4 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Thu, 23 Jan 2025 14:54:12 +0100 Subject: perf: pass context to importer for better tracing --- internal/importer/main.go | 3 ++- internal/importer/main_test.go | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'internal') diff --git a/internal/importer/main.go b/internal/importer/main.go index dfa2477..2af1666 100644 --- a/internal/importer/main.go +++ b/internal/importer/main.go @@ -144,6 +144,7 @@ func createSourceImporter( } func Start( + ctx context.Context, cfg *config.Config, log *log.Logger, indexer *index.WriteIndex, @@ -158,7 +159,7 @@ func Start( log.Debug("starting importer", "timeout", cfg.Importer.Timeout.Duration) importCtx, cancelImport := context.WithTimeout( - context.Background(), + ctx, cfg.Importer.Timeout.Duration, ) defer cancelImport() diff --git a/internal/importer/main_test.go b/internal/importer/main_test.go index 0bc438d..9e19b8c 100644 --- a/internal/importer/main_test.go +++ b/internal/importer/main_test.go @@ -1,6 +1,7 @@ package importer import ( + "context" "testing" "go.alanpearce.eu/searchix/internal/config" @@ -21,7 +22,14 @@ func BenchmarkImporterLowMemory(b *testing.B) { b.Fatal(err) } - err = Start(&cfg, logger.Named("importer"), write, false, &[]string{"nixpkgs"}) + err = Start( + context.Background(), + &cfg, + logger.Named("importer"), + write, + false, + &[]string{"nixpkgs"}, + ) if err != nil { b.Fatal(err) } -- cgit 1.4.1