lens @ 1d6fa60b3c60d068d12b19f10f5ad73e836b5a70

feat: Add scheduler again

Since I have fixed the issue with the `SIGTINT` hanging the application
I can readd the scheduler once more.

Also move the param for amount of scheduler work.
diff --git a/Makefile b/Makefile
index 5731808468bf7f1964698229f3399874c8ec2bab..85f22dddfe0ecd5ab13f28f73809d211ea651757 100644
--- a/Makefile
+++ b/Makefile
@@ -13,9 +13,7 @@ 	$(GO_BUILD) -o $(OUT) $(SERVER)
 
 run: sass
 	$(GO_RUN) $(SERVER) \
-		--db-type psql \
-		--db-con "host=localhost user=gabrielgio password=diablo123 dbname=img port=5432 sslmode=disable" \
-		--log-level trace \
+		--log-level error \
 		--aes-key=6368616e676520746869732070617373 \
 		--root=${HOME}
 
diff --git a/cmd/server/main.go b/cmd/server/main.go
index 0abdc09c74554ffe96c2e8d04b63a68923f41f12..8b1cc00b276dd02ccef3e57c08aa8655b05eb15e 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -28,10 +28,11 @@ )
 
 func main() {
 	var (
-		key      = flag.String("aes-key", "", "AES key, either 16, 24, or 32 bytes string to select AES-128, AES-192, or AES-256")
-		dbType   = flag.String("db-type", "sqlite", "Database to be used. Choose either mysql, psql or sqlite")
-		dbCon    = flag.String("db-con", "main.db", "Database string connection for given database type. Ref: https://gorm.io/docs/connecting_to_the_database.html")
-		logLevel = flag.String("log-level", "error", "Log level: Choose either trace, debug, info, warning, error, fatal or panic")
+		key            = flag.String("aes-key", "", "AES key, either 16, 24, or 32 bytes string to select AES-128, AES-192, or AES-256")
+		dbType         = flag.String("db-type", "sqlite", "Database to be used. Choose either mysql, psql or sqlite")
+		dbCon          = flag.String("db-con", "main.db", "Database string connection for given database type. Ref: https://gorm.io/docs/connecting_to_the_database.html")
+		logLevel       = flag.String("log-level", "error", "Log level: Choose either trace, debug, info, warning, error, fatal or panic")
+		schedulerCount = flag.Uint("scheduler-count", 10, "How many workers are created to process media files")
 
 		// TODO: this will later be replaced by user specific root folder
 		root = flag.String("root", "", "root folder for the whole application. All the workers will use it as working directory")
@@ -79,7 +80,7 @@ 	extRouter.AddMiddleware(logMiddleware.HTTP)
 	extRouter.AddMiddleware(authMiddleware.LoggedIn)
 	extRouter.AddMiddleware(ext.HTML)
 
-	scheduler := worker.NewScheduler(10)
+	scheduler := worker.NewScheduler(*schedulerCount)
 
 	// repository
 	var (
diff --git a/pkg/coroutines/coroutines.go b/pkg/coroutines/coroutines.go
new file mode 100644
index 0000000000000000000000000000000000000000..c0f7247cdf3d00e2b1fd4e019f5ec334fa32ea96
--- /dev/null
+++ b/pkg/coroutines/coroutines.go
@@ -0,0 +1 @@
+package coroutines
diff --git a/pkg/worker/list_processor.go b/pkg/worker/list_processor.go
index d53b7ea6a8e4a051ecd7c210e70c77cc97454900..8169e4e8b7cb5409083015fc21c9a9c7f6d354e7 100644
--- a/pkg/worker/list_processor.go
+++ b/pkg/worker/list_processor.go
@@ -2,6 +2,8 @@ package worker
 
 import (
 	"context"
+	"errors"
+	"sync"
 )
 
 type (
@@ -64,18 +66,21 @@
 		if len(values) == 0 {
 			return nil
 		}
+		var wg sync.WaitGroup
 
 		for _, v := range values {
-			select {
-			case <-ctx.Done():
-				return ctx.Err()
-			default:
-			}
+			wg.Add(1)
+			l.scheduler.Take()
+			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())
+				}
+			}(v)
+		}
 
-			if err := l.listProcessor.Process(ctx, v); err != nil {
-				return err
-			}
-		}
+		wg.Wait()
 	}
 }
 
diff --git a/pkg/worker/scheduler.go b/pkg/worker/scheduler.go
index b410b33714bcb0541a668f7af10fcce82b1dcf0b..2ce86feffdc778dd277dc943a4ed48077aaac41f 100644
--- a/pkg/worker/scheduler.go
+++ b/pkg/worker/scheduler.go
@@ -1,13 +1,7 @@
 package worker
 
-import (
-	"fmt"
-	"sync/atomic"
-)
-
 type Scheduler struct {
-	pool  chan any
-	count atomic.Int64
+	pool chan any
 }
 
 func NewScheduler(count uint) *Scheduler {
@@ -18,12 +12,8 @@ }
 
 func (self *Scheduler) Take() {
 	self.pool <- nil
-	self.count.Add(1)
-	fmt.Printf("<- %d\n", self.count.Load())
 }
 
 func (self *Scheduler) Return() {
 	<-self.pool
-	self.count.Add(-1)
-	fmt.Printf("-> %d\n", self.count.Load())
 }