diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-16 16:32:31 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-16 16:32:31 +0200 |
commit | da992500f806bb87b06559d920ee12b7680955ee (patch) | |
tree | d535f986eba7a95e5cb6b358259bc37ca6fa7ca9 /controller | |
parent | 64496464b3812839c1e4b440bdf69cc84f39c491 (diff) | |
download | mdir-da992500f806bb87b06559d920ee12b7680955ee.tar.gz mdir-da992500f806bb87b06559d920ee12b7680955ee.tar.bz2 mdir-da992500f806bb87b06559d920ee12b7680955ee.zip |
feat: Add worker
Add a simple worker to manage a work queue. Right now, it is bit
brittled and has no test coverage yet, but it works.
Also moved from pico.css to bulma, I like the idea of classes approach
of pico but for me bulma yields a better result.
Diffstat (limited to 'controller')
-rw-r--r-- | controller/controller.go | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/controller/controller.go b/controller/controller.go index 252be73..3e029f0 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -1,24 +1,16 @@ package controller import ( - "context" "net/http" "git.sr.ht/~gabrielgio/midr/db" - "git.sr.ht/~gabrielgio/midr/yt" - work "git.sr.ht/~sircmpwn/dowork" + "git.sr.ht/~gabrielgio/midr/worker" "github.com/gin-gonic/gin" ) type Env struct { Entries db.EntryModel -} - -func spawnWorker(link string, output string) { - work.Submit(func(ctx context.Context) error { - yt.RunYtDlpProcess(link, output) - return nil - }) + Worker worker.Worker } func (e Env) GetEntries(c *gin.Context) { @@ -28,8 +20,12 @@ func (e Env) GetEntries(c *gin.Context) { func (e *Env) GetEntry(c *gin.Context) { id := c.Param("id") - entry := e.Entries.Find(id) - c.HTML(http.StatusOK, "entry", entry) + if id != "" { + entry := e.Entries.Find(id) + c.HTML(http.StatusOK, "entry", entry) + } else { + c.HTML(http.StatusOK, "entry", db.Entry{}) + } } func (e *Env) UpdateEntry(c *gin.Context) { @@ -43,7 +39,7 @@ func (e *Env) CreateEntry(c *gin.Context) { var entry db.Entry c.ShouldBind(&entry) e.Entries.Create(entry) - spawnWorker(entry.Link, entry.OutputFolder) + e.Worker.SpawnWorker(entry.ID, entry.Link, entry.OutputFolder) c.Redirect(http.StatusFound, "/") } |