Implement download queue (default size 2) and cleanup old entries after a while

This commit is contained in:
2021-11-21 16:19:49 +10:30
parent d1f92abb16
commit e8a4f41ca2
5 changed files with 131 additions and 13 deletions

14
main.go
View File

@@ -19,7 +19,7 @@ import (
"github.com/tardisx/gropple/version"
)
var downloads []*download.Download
var downloads download.Downloads
var downloadId = 0
var conf *config.Config
@@ -82,6 +82,16 @@ func main() {
}
}()
// start downloading queued downloads when slots available, and clean up
// old entries
go func() {
for {
downloads.StartQueued(conf.Server.MaximumActiveDownloads)
downloads = downloads.Cleanup()
time.Sleep(time.Second)
}
}()
log.Printf("starting gropple %s - https://github.com/tardisx/gropple", versionInfo.CurrentVersion)
log.Printf("go to %s for details on installing the bookmarklet and to check status", conf.Server.Address)
log.Fatal(srv.ListenAndServe())
@@ -220,7 +230,7 @@ func fetchInfoOneRESTHandler(w http.ResponseWriter, r *http.Request) {
// set the profile
thisDownload.DownloadProfile = *profile
go func() { thisDownload.Begin() }()
thisDownload.Queue()
succRes := successResponse{Success: true, Message: "download started"}
succResB, _ := json.Marshal(succRes)
w.Write(succResB)