1. Download all works instantly

2. Display queue status
pull/24/head
Akhil Gupta 4 years ago
parent 421d7ed407
commit ebb323819d

@ -1,3 +1,3 @@
CONFIG=. CONFIG=.
DATA=./assets DATA=./assets
CHECK_FREQUENCY = 240 CHECK_FREQUENCY = 10

@ -67,11 +67,21 @@
<p class="useMore">{{ .Summary }}</p> <p class="useMore">{{ .Summary }}</p>
<div class="row"> <div class="row">
<div class="columns three"> <div class="columns four">
Last Ep : {{ latestEpisodeDate .PodcastItems}} Last Ep : {{ latestEpisodeDate .PodcastItems}}
</div> </div>
<div class="columns three">{{ len .PodcastItems }} episodes</div> {{$downloading:=downloadingEpisodes .PodcastItems}}
<div class="columns six" style="text-align: right"> <div
class="columns five"
title="{{downloadedEpisodes .PodcastItems}} episodes downloaded out of total {{ len .PodcastItems}} episodes.
{{if gt $downloading 0}} {{$downloading}} episodes in queue {{end}}
"
>
{{if gt $downloading 0}} ({{$downloading}})/{{end}}{{downloadedEpisodes .PodcastItems}}/{{ len .PodcastItems }} episodes
</div>
<div class="columns three" style="">
<button <button
class="button button-delete" class="button button-delete"
onclick="deletePodcast('{{.ID}}')" onclick="deletePodcast('{{.ID}}')"

@ -101,6 +101,7 @@ func DownloadAllEpisodesByPodcastId(c *gin.Context) {
err := db.SetAllEpisodesToDownload(searchByIdQuery.Id) err := db.SetAllEpisodesToDownload(searchByIdQuery.Id)
fmt.Println(err) fmt.Println(err)
go service.RefreshEpisodes()
c.JSON(200, gin.H{}) c.JSON(200, gin.H{})
} else { } else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})

@ -2,6 +2,7 @@ package db
import ( import (
"errors" "errors"
"fmt"
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
@ -165,17 +166,21 @@ func Unlock(name string) {
} }
func UnlockMissedJobs() { func UnlockMissedJobs() {
var jobLocks *[]JobLock var jobLocks []JobLock
result := DB.Where("date != ", time.Time{}).Find(&jobLocks) result := DB.Debug().Find(&jobLocks)
if result.Error != nil { if result.Error != nil {
return return
} }
for _, job := range *jobLocks { for _, job := range jobLocks {
if (job.Date == time.Time{}) {
continue
}
var duration time.Duration var duration time.Duration
duration = time.Duration(job.Duration) duration = time.Duration(job.Duration)
d := job.Date.Add(time.Minute * duration) d := job.Date.Add(time.Minute * duration)
if d.Before(time.Now()) { if d.Before(time.Now()) {
fmt.Println(job.Name + " is unlocked")
Unlock(job.Name) Unlock(job.Name)
} }
} }

@ -50,6 +50,24 @@ func main() {
} }
return latest.Format("Jan 2 2006") return latest.Format("Jan 2 2006")
}, },
"downloadedEpisodes": func(podcastItems []db.PodcastItem) int {
count := 0
for _, item := range podcastItems {
if item.DownloadStatus == db.Downloaded {
count++
}
}
return count
},
"downloadingEpisodes": func(podcastItems []db.PodcastItem) int {
count := 0
for _, item := range podcastItems {
if item.DownloadStatus == db.NotDownloaded {
count++
}
}
return count
},
"formatDuration": func(total int) string { "formatDuration": func(total int) string {
if total <= 0 { if total <= 0 {
return "" return ""
@ -120,9 +138,11 @@ func intiCron() {
checkFrequency = 30 checkFrequency = 30
log.Print(err) log.Print(err)
} }
service.UnlockMissedJobs()
//gocron.Every(uint64(checkFrequency)).Minutes().Do(service.DownloadMissingEpisodes) //gocron.Every(uint64(checkFrequency)).Minutes().Do(service.DownloadMissingEpisodes)
gocron.Every(uint64(checkFrequency)).Minutes().Do(service.RefreshEpisodes) gocron.Every(uint64(checkFrequency)).Minutes().Do(service.RefreshEpisodes)
gocron.Every(uint64(checkFrequency)).Minutes().Do(service.CheckMissingFiles) gocron.Every(uint64(checkFrequency)).Minutes().Do(service.CheckMissingFiles)
gocron.Every(uint64(checkFrequency) * 2).Minutes().Do(service.UnlockMissedJobs)
gocron.Every(2).Days().Do(service.CreateBackup) gocron.Every(2).Days().Do(service.CreateBackup)
<-gocron.Start() <-gocron.Start()
} }

@ -431,3 +431,7 @@ func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload b
return db.UpdateSettings(setting) return db.UpdateSettings(setting)
} }
func UnlockMissedJobs() {
db.UnlockMissedJobs()
}

Loading…
Cancel
Save