From f1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Mon, 13 Jun 2022 21:03:34 +0200 Subject: 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. --- controller/controller.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'controller/controller.go') 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) { -- cgit v1.2.3