diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-07-22 15:25:27 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-07-22 15:25:27 +0200 |
commit | 1e984fc8ced6a5915dbd7b6e17bd942e8438cf27 (patch) | |
tree | 1dbb64f3438030e3b1a3a45e728e73ee74787279 /controller | |
parent | 90d9d819b70f68e10482954cfc461737c0165f8a (diff) | |
download | mdir-1e984fc8ced6a5915dbd7b6e17bd942e8438cf27.tar.gz mdir-1e984fc8ced6a5915dbd7b6e17bd942e8438cf27.tar.bz2 mdir-1e984fc8ced6a5915dbd7b6e17bd942e8438cf27.zip |
ref: Move the yt manager to the worker
Simplify the worker/manager relationship. Now the worker is responsible
for the managing the yt-dlp process as well.
Also introduce chan to report back logs. That is an attempt to decouple
things.
Diffstat (limited to 'controller')
-rw-r--r-- | controller/controller.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/controller/controller.go b/controller/controller.go index c7f4145..701d34c 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -1,8 +1,10 @@ package controller import ( + "log" "net/http" "strconv" + "strings" "time" "git.sr.ht/~gabrielgio/midr/db" @@ -15,6 +17,13 @@ type Env struct { Worker worker.Worker } +func logBytes(logc <-chan []byte) { + for l := range logc { + logs := strings.TrimRight(string(l), "\t \n") + log.Println(logs) + } +} + func (e *Env) GetEntries(c *gin.Context) { entries := e.Entries.All() c.HTML(http.StatusOK, "index", entries) @@ -41,7 +50,9 @@ func (e *Env) CreateEntry(c *gin.Context) { var entry db.Entry c.ShouldBind(&entry) e.Entries.Create(&entry) - e.Worker.SpawnWorker(&entry) + log := e.Worker.RunYtDlpWorker(&entry) + go logBytes(log) + c.Redirect(http.StatusFound, "/") } @@ -66,7 +77,10 @@ func (e *Env) StartScheduler() { entries := e.Entries.All() for _, entry := range entries { - e.Worker.SpawnWorker(&entry) + log := e.Worker.RunYtDlpWorker(&entry) + if log != nil { + go logBytes(log) + } } time.Sleep(30 * time.Second) } |