about summary refs log tree commit diff stats
path: root/internal/importer
diff options
context:
space:
mode:
authorAlan Pearce2024-05-13 21:50:14 +0200
committerAlan Pearce2024-05-13 22:25:46 +0200
commit6b40e0c0fa90f11be14a93f1d6275779fd645cac (patch)
tree0df5bea87242450829ca441d235c077a0e09a149 /internal/importer
parent2722f24af87f437ed9fcb8cc743ad1784141fd3a (diff)
downloadsearchix-6b40e0c0fa90f11be14a93f1d6275779fd645cac.tar.lz
searchix-6b40e0c0fa90f11be14a93f1d6275779fd645cac.tar.zst
searchix-6b40e0c0fa90f11be14a93f1d6275779fd645cac.zip
refactor: combine import and web server into one binary
Diffstat (limited to 'internal/importer')
-rw-r--r--internal/importer/channel.go4
-rw-r--r--internal/importer/importer.go6
-rw-r--r--internal/importer/main.go16
-rw-r--r--internal/importer/nixpkgs-channel.go4
4 files changed, 10 insertions, 20 deletions
diff --git a/internal/importer/channel.go b/internal/importer/channel.go
index fb6668c..1bce1b0 100644
--- a/internal/importer/channel.go
+++ b/internal/importer/channel.go
@@ -9,7 +9,7 @@ import (
 	"path"
 	"searchix/internal/config"
 	"searchix/internal/file"
-	"searchix/internal/search"
+	"searchix/internal/index"
 	"strconv"
 	"strings"
 
@@ -81,7 +81,7 @@ func (i *ChannelImporter) FetchIfNeeded(parent context.Context) (bool, error) {
 	return before != after, nil
 }
 
-func (i *ChannelImporter) Import(parent context.Context, indexer *search.WriteIndex) (bool, error) {
+func (i *ChannelImporter) Import(parent context.Context, indexer *index.WriteIndex) (bool, error) {
 	if i.Source.OutputPath == "" {
 		return false, errors.New("no output path specified")
 	}
diff --git a/internal/importer/importer.go b/internal/importer/importer.go
index 5f251b0..a242481 100644
--- a/internal/importer/importer.go
+++ b/internal/importer/importer.go
@@ -5,13 +5,13 @@ import (
 	"log/slog"
 	"path"
 	"searchix/internal/config"
-	"searchix/internal/search"
+	"searchix/internal/index"
 	"sync"
 )
 
 type Importer interface {
 	FetchIfNeeded(context.Context) (bool, error)
-	Import(context.Context, *search.WriteIndex) (bool, error)
+	Import(context.Context, *index.WriteIndex) (bool, error)
 }
 
 func NewNixpkgsChannelImporter(
@@ -50,7 +50,7 @@ type importConfig struct {
 
 func processOptions(
 	parent context.Context,
-	indexer *search.WriteIndex,
+	indexer *index.WriteIndex,
 	conf *importConfig,
 ) (bool, error) {
 	ctx, cancel := context.WithTimeout(parent, conf.Source.ImportTimeout)
diff --git a/internal/importer/main.go b/internal/importer/main.go
index a6f15e9..2d87e33 100644
--- a/internal/importer/main.go
+++ b/internal/importer/main.go
@@ -8,23 +8,18 @@ import (
 	"os/exec"
 	"path"
 	"searchix/internal/config"
-	"searchix/internal/search"
+	"searchix/internal/index"
 	"strings"
 )
 
-func Start(cfg *config.Config, replace bool) error {
+func Start(cfg *config.Config, indexer *index.WriteIndex, replace bool) error {
 	if len(cfg.Importer.Sources) == 0 {
 		slog.Info("No sources enabled")
 
 		return nil
 	}
 
-	indexer, err := search.NewIndexer(cfg.DataPath, replace)
-	if err != nil {
-		log.Fatalf("Failed to create indexer: %v", err)
-	}
-
-	ctx, cancel := context.WithTimeout(context.Background(), cfg.Importer.Timeout)
+	ctx, cancel := context.WithTimeout(context.Background(), cfg.Importer.Timeout.Duration)
 	defer cancel()
 
 	var imp Importer
@@ -81,10 +76,5 @@ func Start(cfg *config.Config, replace bool) error {
 		}
 	}
 
-	err = indexer.Close()
-	if err != nil {
-		slog.Error("error closing indexer", "error", err)
-	}
-
 	return nil
 }
diff --git a/internal/importer/nixpkgs-channel.go b/internal/importer/nixpkgs-channel.go
index 7aaa816..d302154 100644
--- a/internal/importer/nixpkgs-channel.go
+++ b/internal/importer/nixpkgs-channel.go
@@ -9,7 +9,7 @@ import (
 	"path"
 	"searchix/internal/config"
 	"searchix/internal/file"
-	"searchix/internal/search"
+	"searchix/internal/index"
 
 	"github.com/pkg/errors"
 )
@@ -65,7 +65,7 @@ func (i *NixpkgsChannelImporter) FetchIfNeeded(parent context.Context) (bool, er
 
 func (i *NixpkgsChannelImporter) Import(
 	parent context.Context,
-	indexer *search.WriteIndex,
+	indexer *index.WriteIndex,
 ) (bool, error) {
 	filename := path.Join(i.DataPath, filesToFetch["options"])
 	revFilename := path.Join(i.DataPath, filesToFetch["revision"])