From 4e5b2d9dfd9413ce084e64e048a57ad6e23356d3 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Mon, 20 Jun 2022 18:35:50 +0200 Subject: ref: Remove model dependency fom worker It was a bit weird to have that dependency in first place. --- worker/worker.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'worker/worker.go') diff --git a/worker/worker.go b/worker/worker.go index 06fac36..a8f1518 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -2,9 +2,7 @@ package worker import ( "context" - "time" - "git.sr.ht/~gabrielgio/midr/db" "git.sr.ht/~gabrielgio/midr/yt" work "git.sr.ht/~sircmpwn/dowork" ) @@ -34,6 +32,13 @@ type Job struct { Status string } +func NewWorkder() Worker { + return Worker{ + c: make(chan command, 10), + jobs: make(map[uint]string), + } +} + func (w *Worker) CanEnqueue(index uint) bool { v, found := w.jobs[index] return !found || v == statusNotQueued @@ -73,21 +78,8 @@ func (w *Worker) startReader() { } } -func (w *Worker) startScheduler(model db.EntryModel) { - for true { - entries := model.All() - for _, e := range entries { - w.SpawnWorker(e.ID, e.Link, e.OutputFolder) - } - time.Sleep(30 * time.Minute) - } -} - -func (w *Worker) StartWorker(model db.EntryModel) { - w.c = make(chan command, 10) - w.jobs = make(map[uint]string) +func (w *Worker) StartReader() { go w.startReader() - go w.startScheduler(model) } func (w *Worker) GetJobs() []Job { -- cgit v1.2.3