diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-20 18:35:50 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-20 18:35:50 +0200 |
commit | 4e5b2d9dfd9413ce084e64e048a57ad6e23356d3 (patch) | |
tree | 674754d58838a219871304fd8fc57b44d2193160 /worker | |
parent | a4cd5de795926537318f94aa34c9f2579c29fc11 (diff) | |
download | mdir-4e5b2d9dfd9413ce084e64e048a57ad6e23356d3.tar.gz mdir-4e5b2d9dfd9413ce084e64e048a57ad6e23356d3.tar.bz2 mdir-4e5b2d9dfd9413ce084e64e048a57ad6e23356d3.zip |
ref: Remove model dependency fom worker
It was a bit weird to have that dependency in first place.
Diffstat (limited to 'worker')
-rw-r--r-- | worker/worker.go | 24 |
1 files changed, 8 insertions, 16 deletions
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 { |