diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-07-13 12:22:15 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-07-13 12:22:15 +0200 |
commit | 90d9d819b70f68e10482954cfc461737c0165f8a (patch) | |
tree | fa5dd5b15c0c5a53d084c7b4be9fc2d7d6782491 /worker | |
parent | 4e5b2d9dfd9413ce084e64e048a57ad6e23356d3 (diff) | |
download | mdir-90d9d819b70f68e10482954cfc461737c0165f8a.tar.gz mdir-90d9d819b70f68e10482954cfc461737c0165f8a.tar.bz2 mdir-90d9d819b70f68e10482954cfc461737c0165f8a.zip |
feat: Add custom css
Diffstat (limited to 'worker')
-rw-r--r-- | worker/worker.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/worker/worker.go b/worker/worker.go index a8f1518..2444e89 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -3,6 +3,7 @@ package worker import ( "context" + "git.sr.ht/~gabrielgio/midr/db" "git.sr.ht/~gabrielgio/midr/yt" work "git.sr.ht/~sircmpwn/dowork" ) @@ -34,7 +35,7 @@ type Job struct { func NewWorkder() Worker { return Worker{ - c: make(chan command, 10), + c: make(chan command), jobs: make(map[uint]string), } } @@ -44,26 +45,31 @@ func (w *Worker) CanEnqueue(index uint) bool { return !found || v == statusNotQueued } -func (w *Worker) SpawnWorker(index uint, link string, output string) { +func (w *Worker) RemoveJob(id uint) { + delete(w.jobs, id) +} + +func (w *Worker) SpawnWorker(entry *db.Entry) { - if !w.CanEnqueue(index) { + if !w.CanEnqueue(entry.ID) { return } - w.c <- command{action: commandEnqueue, index: index} + w.c <- command{action: commandEnqueue, index: entry.ID} task := work.NewTask(func(ctx context.Context) error { - w.c <- command{action: commandStart, index: index} - yt.RunYtDlpProcess(link, output) + + w.c <- command{action: commandStart, index: entry.ID} + yt.RunYtDlpProcess(entry) return nil }).After(func(ctx context.Context, task *work.Task) { - w.c <- command{action: commandDequeue, index: index} + w.c <- command{action: commandDequeue, index: entry.ID} }) work.Enqueue(task) } func (w *Worker) startReader() { - for true { + for { command := <-w.c if command.action == commandEnqueue { |