diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-19 16:24:42 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-19 16:28:43 +0200 |
commit | b242ed3c44f4dde7c4b452312b78a3b02f42ea65 (patch) | |
tree | 1a9cc1b68e4a94e530c5e2596c645a698c4a656e /cmd/server | |
parent | 84f80cdc4d27c3274c74f98255bf90c713e89a85 (diff) | |
download | lens-b242ed3c44f4dde7c4b452312b78a3b02f42ea65.tar.gz lens-b242ed3c44f4dde7c4b452312b78a3b02f42ea65.tar.bz2 lens-b242ed3c44f4dde7c4b452312b78a3b02f42ea65.zip |
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.
Diffstat (limited to 'cmd/server')
-rw-r--r-- | cmd/server/main.go | 25 |
1 files changed, 13 insertions, 12 deletions
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() |