aboutsummaryrefslogtreecommitdiff
path: root/controller/controller.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2022-06-13 21:03:34 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2022-06-13 21:07:54 +0200
commitf1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5 (patch)
tree7d9fe5031671cdf5fd8da3e031966c72a358942e /controller/controller.go
parentf13a07aa433298de91e1c4aff68f72be6d851be2 (diff)
downloadmdir-f1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5.tar.gz
mdir-f1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5.tar.bz2
mdir-f1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5.zip
feat: Add poor implementation for the worker
This is just me testing a bit how doworker works, while I learn of go/gin in the process.
Diffstat (limited to 'controller/controller.go')
-rw-r--r--controller/controller.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/controller/controller.go b/controller/controller.go
index f89d267..3552304 100644
--- a/controller/controller.go
+++ b/controller/controller.go
@@ -1,12 +1,22 @@
package controller
import (
+ "context"
"net/http"
+ "git.sr.ht/~gabrielgio/midr/db"
+ "git.sr.ht/~gabrielgio/midr/yt"
+ work "git.sr.ht/~sircmpwn/dowork"
"github.com/gin-gonic/gin"
- "gitlab.com/gabrielgio/midr/db"
)
+func spawnWorker(link string, output string) {
+ work.Submit(func(ctx context.Context) error {
+ yt.RunYtDlpProcess(link, output)
+ return nil
+ })
+}
+
func GetEntries(c *gin.Context) {
var entries []db.YdlEntry
db.DB.Find(&entries)
@@ -32,8 +42,8 @@ func CreateEntry(c *gin.Context) {
var entry db.YdlEntry
c.ShouldBind(&entry)
db.DB.Create(&entry)
+ spawnWorker(entry.Link, entry.Output_folder)
c.Redirect(http.StatusFound, "/")
-
}
func DeleteEntry(c *gin.Context) {