From b242ed3c44f4dde7c4b452312b78a3b02f42ea65 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Sat, 19 Aug 2023 16:24:42 +0200 Subject: feat: Add task loop Now the tasks will loop every given time. With this it will be able to pick up new photos after the application was started. I added 2h for file because my personal photo gallery is quite big and quite IO bottled necked so it tasks a lot of time to go through. --- cmd/server/main.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'cmd') diff --git a/cmd/server/main.go b/cmd/server/main.go index daf5356..2a93946 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "os/signal" + "time" "github.com/gorilla/mux" "github.com/sirupsen/logrus" @@ -122,37 +123,37 @@ func main() { albumScanner = scanner.NewAlbumScanner(mediaRepository) ) - // worker + // tasks var ( - serverWorker = worker.NewServerWorker(&http.Server{Handler: r, Addr: "0.0.0.0:8080"}) - fileWorker = worker.NewWorkerFromChanProcessor[string]( + serverTask = worker.NewServerTask(&http.Server{Handler: r, Addr: "0.0.0.0:8080"}) + fileTask = worker.NewTaskFromChanProcessor[string]( fileScanner, scheduler, logrus.WithField("context", "file scanner"), ) - exifWorker = worker.NewWorkerFromBatchProcessor[*repository.Media]( + exifTask = worker.NewTaskFromBatchProcessor[*repository.Media]( exifScanner, scheduler, logrus.WithField("context", "exif scanner"), ) - thumbnailWorker = worker.NewWorkerFromBatchProcessor[*repository.Media]( + thumbnailTask = worker.NewTaskFromBatchProcessor[*repository.Media]( thumbnailScanner, scheduler, logrus.WithField("context", "thumbnail scanner"), ) - albumWorker = worker.NewWorkerFromSerialProcessor[*repository.Media]( + albumTask = worker.NewTaskFromSerialProcessor[*repository.Media]( albumScanner, scheduler, logrus.WithField("context", "thumbnail scanner"), ) ) - pool := worker.NewWorkerPool() - pool.AddWorker("http server", serverWorker) - pool.AddWorker("exif scanner", exifWorker) - pool.AddWorker("file scanner", fileWorker) - pool.AddWorker("thumbnail scanner", thumbnailWorker) - pool.AddWorker("album scanner", albumWorker) + pool := worker.NewTaskPool() + pool.AddTask("http server", time.Minute, serverTask) + pool.AddTask("exif scanner", 15*time.Minute, exifTask) + pool.AddTask("file scanner", 2*time.Hour, fileTask) + pool.AddTask("thumbnail scanner", 15*time.Minute, thumbnailTask) + pool.AddTask("album scanner", 15*time.Minute, albumTask) ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) defer stop() -- cgit v1.2.3