diff options
Diffstat (limited to 'pkg/worker')
-rw-r--r-- | pkg/worker/exif_scanner.go | 2 | ||||
-rw-r--r-- | pkg/worker/file_scanner.go | 6 | ||||
-rw-r--r-- | pkg/worker/list_processor_test.go | 2 | ||||
-rw-r--r-- | pkg/worker/worker.go | 4 |
4 files changed, 10 insertions, 4 deletions
diff --git a/pkg/worker/exif_scanner.go b/pkg/worker/exif_scanner.go index 66091cd..6d40dbd 100644 --- a/pkg/worker/exif_scanner.go +++ b/pkg/worker/exif_scanner.go @@ -15,7 +15,7 @@ type ( var _ ListProcessor[*media.Media] = &EXIFScanner{} -func NewEXIFScanner(root string, repository media.Repository) *EXIFScanner { +func NewEXIFScanner(repository media.Repository) *EXIFScanner { return &EXIFScanner{ repository: repository, } diff --git a/pkg/worker/file_scanner.go b/pkg/worker/file_scanner.go index 321fbca..0dc2eb2 100644 --- a/pkg/worker/file_scanner.go +++ b/pkg/worker/file_scanner.go @@ -33,6 +33,12 @@ func (f *FileScanner) Query(ctx context.Context) (<-chan string, error) { go func() { defer close(c) _ = filepath.Walk(f.root, func(path string, info fs.FileInfo, err error) error { + select { + case <-ctx.Done(): + return filepath.SkipAll + default: + } + if info.IsDir() && filepath.Base(info.Name())[0] == '.' { return filepath.SkipDir } diff --git a/pkg/worker/list_processor_test.go b/pkg/worker/list_processor_test.go index b7373d1..1e4ed2d 100644 --- a/pkg/worker/list_processor_test.go +++ b/pkg/worker/list_processor_test.go @@ -1,4 +1,4 @@ -// go:build unit +//go:build unit package worker diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index c52f0be..18cc0e2 100644 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -36,12 +36,12 @@ func (self *WorkerPool) AddWorker(name string, worker Worker) { } func (self *WorkerPool) Start(ctx context.Context) { + self.wg.Add(len(self.workers)) for _, w := range self.workers { - self.wg.Add(1) go func(w *Work) { defer self.wg.Done() if err := w.Worker.Start(ctx); err != nil && !errors.Is(err, context.Canceled) { - fmt.Println("Error ", w.Name, err.Error()) + fmt.Println("Processes finished, error", w.Name, err.Error()) } else { fmt.Println(w.Name, "done") } |