diff --git a/cmd/server/main.go b/cmd/server/main.go
index 8b1cc00b276dd02ccef3e57c08aa8655b05eb15e..54a7ba05d479b9184ccf4c363fb1e4f091d68a75 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -109,17 +109,27 @@ } {
v.SetMyselfIn(extRouter)
}
+ // processors
+ var (
+ fileScanner = worker.NewFileScanner(*root, mediaRepository)
+ exifScanner = worker.NewEXIFScanner(mediaRepository)
+ )
+
// worker
var (
serverWorker = worker.NewServerWorker(&fasthttp.Server{Handler: r.Handler})
- fileScanner = worker.NewFileScanner(*root, mediaRepository)
- exifScanner = worker.NewEXIFScanner(mediaRepository)
+ fileWorker = worker.NewWorkerFromChanProcessor[string](fileScanner, scheduler)
+ exifWorker = worker.NewWorkerFromListProcessor[*media.Media](
+ exifScanner,
+ scheduler,
+ logrus.WithField("context", "exif scanner"),
+ )
)
pool := worker.NewWorkerPool()
pool.AddWorker("http server", serverWorker)
- pool.AddWorker("exif scanner", worker.NewWorkerFromListProcessor[*media.Media](exifScanner, scheduler))
- pool.AddWorker("file scanner", worker.NewWorkerFromChanProcessor[string](fileScanner, scheduler))
+ pool.AddWorker("exif scanner", exifWorker)
+ pool.AddWorker("file scanner", fileWorker)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
diff --git a/pkg/worker/list_processor.go b/pkg/worker/list_processor.go
index 8169e4e8b7cb5409083015fc21c9a9c7f6d354e7..c9c20a9d5b27b2f855df75ce8e98527973c51a96 100644
--- a/pkg/worker/list_processor.go
+++ b/pkg/worker/list_processor.go
@@ -4,6 +4,8 @@ import (
"context"
"errors"
"sync"
+
+ "github.com/sirupsen/logrus"
)
type (
@@ -26,6 +28,7 @@ }
listProcessorWorker[T any] struct {
listProcessor ListProcessor[T]
+ logrus *logrus.Entry
scheduler *Scheduler
}
)
@@ -33,10 +36,12 @@
func NewWorkerFromListProcessor[T any](
listProcessor ListProcessor[T],
scheduler *Scheduler,
+ logrus *logrus.Entry,
) Worker {
return &listProcessorWorker[T]{
listProcessor: listProcessor,
scheduler: scheduler,
+ logrus: logrus,
}
}
@@ -75,7 +80,7 @@ go func(v T) {
defer l.scheduler.Return()
defer wg.Done()
if err := l.listProcessor.Process(ctx, v); err != nil && !errors.Is(err, context.Canceled) {
- println("Err", err.Error())
+ l.logrus.WithError(err).Error("Error processing batch")
}
}(v)
}