Implement download queue (default size 2) and cleanup old entries after a while
This commit is contained in:
14
main.go
14
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user