1diff --git a/controller/controller.go b/controller/controller.go
2index 7fc874847299fe4623b4e2754425bca2b00cd806..e381bf81c9f1386fcbdb5ad9f45629b5bd1890d9 100644
3--- a/controller/controller.go
4+++ b/controller/controller.go
5@@ -2,6 +2,7 @@ package controller
6
7 import (
8 "net/http"
9+ "time"
10
11 "git.sr.ht/~gabrielgio/midr/db"
12 "git.sr.ht/~gabrielgio/midr/worker"
13@@ -13,7 +14,7 @@ Entries db.EntryModel
14 Worker worker.Worker
15 }
16
17-func (e Env) GetEntries(c *gin.Context) {
18+func (e *Env) GetEntries(c *gin.Context) {
19 entries := e.Entries.All()
20 c.HTML(http.StatusOK, "index", entries)
21 }
22@@ -54,3 +55,17 @@ func (e *Env) GetJobs(c *gin.Context) {
23 jobs := e.Worker.GetJobs()
24 c.JSON(http.StatusOK, jobs)
25 }
26+
27+func (e *Env) StartScheduler() {
28+ e.Worker.StartReader()
29+ go func() {
30+ for true {
31+ entries := e.Entries.All()
32+
33+ for _, entry := range entries {
34+ e.Worker.SpawnWorker(entry.ID, entry.Link, entry.OutputFolder)
35+ }
36+ time.Sleep(30 * time.Minute)
37+ }
38+ }()
39+}
40diff --git a/db/model.go b/db/model.go
41index 01d9b9f72f6dff2b08fdeac296ee8cd4cb054c3c..0a5ca98a33c029aa1291ab7bced124f13273c95b 100644
42--- a/db/model.go
43+++ b/db/model.go
44@@ -16,27 +16,27 @@ type EntryModel struct {
45 DB *gorm.DB
46 }
47
48-func (m EntryModel) Find(id string) Entry {
49+func (m *EntryModel) Find(id string) Entry {
50 var entry Entry
51 where := "id = " + id
52 m.DB.Where(where).FirstOrInit(&entry)
53 return entry
54 }
55
56-func (m EntryModel) All() []Entry {
57+func (m *EntryModel) All() []Entry {
58 var entries []Entry
59 m.DB.Find(&entries)
60 return entries
61 }
62
63-func (m EntryModel) Create(entry *Entry) {
64+func (m *EntryModel) Create(entry *Entry) {
65 m.DB.Create(entry)
66 }
67
68-func (m EntryModel) Update(entry Entry) {
69+func (m *EntryModel) Update(entry Entry) {
70 m.DB.Save(&entry)
71 }
72
73-func (m EntryModel) Delete(id string) {
74+func (m *EntryModel) Delete(id string) {
75 m.DB.Delete(&Entry{}, id)
76 }
77diff --git a/routes/routes.go b/routes/routes.go
78index 79264c5feebe65217e721bde51938d3c3f9942a1..31384a710be0fbdfe0d26f286cd199a3315b5495 100644
79--- a/routes/routes.go
80+++ b/routes/routes.go
81@@ -10,14 +10,14 @@
82 func HandleRequests() {
83
84 models := db.EntryModel{DB: db.DB}
85- worker := worker.Worker{}
86-
87- worker.StartWorker(models)
88+ worker := worker.NewWorkder()
89
90 env := &controller.Env{
91 Entries: models,
92 Worker: worker,
93 }
94+
95+ env.StartScheduler()
96
97 r := gin.Default()
98 r.LoadHTMLGlob("templates/*")
99diff --git a/worker/worker.go b/worker/worker.go
100index 06fac3601335e04a918fb55124be04b218578df3..a8f15180e1093473163b8eb4ccf274786ea6d380 100644
101--- a/worker/worker.go
102+++ b/worker/worker.go
103@@ -2,9 +2,7 @@ package worker
104
105 import (
106 "context"
107- "time"
108
109- "git.sr.ht/~gabrielgio/midr/db"
110 "git.sr.ht/~gabrielgio/midr/yt"
111 work "git.sr.ht/~sircmpwn/dowork"
112 )
113@@ -32,6 +30,13 @@
114 type Job struct {
115 Id uint
116 Status string
117+}
118+
119+func NewWorkder() Worker {
120+ return Worker{
121+ c: make(chan command, 10),
122+ jobs: make(map[uint]string),
123+ }
124 }
125
126 func (w *Worker) CanEnqueue(index uint) bool {
127@@ -73,21 +78,8 @@ }
128 }
129 }
130
131-func (w *Worker) startScheduler(model db.EntryModel) {
132- for true {
133- entries := model.All()
134- for _, e := range entries {
135- w.SpawnWorker(e.ID, e.Link, e.OutputFolder)
136- }
137- time.Sleep(30 * time.Minute)
138- }
139-}
140-
141-func (w *Worker) StartWorker(model db.EntryModel) {
142- w.c = make(chan command, 10)
143- w.jobs = make(map[uint]string)
144+func (w *Worker) StartReader() {
145 go w.startReader()
146- go w.startScheduler(model)
147 }
148
149 func (w *Worker) GetJobs() []Job {