timer logic to minutes and que download on add

pull/24/head
Akhil Gupta 4 years ago
parent 004d4c84c3
commit 197aaeab01

@ -40,33 +40,6 @@ func main() {
r.GET("/podcastitems", controllers.GetAllPodcastItems)
r.GET("/podcastitems/:id", controllers.GetPodcastItemById)
r.GET("/ping", func(c *gin.Context) {
data, err := service.AddPodcast(c.Query("url"))
go service.AddPodcastItems(&data)
//data, err := db.GetAllPodcastItemsToBeDownloaded()
if err == nil {
c.JSON(200, data)
} else {
c.JSON(http.StatusInternalServerError, err.Error())
}
})
r.GET("/pong", func(c *gin.Context) {
data, err := db.GetAllPodcastItemsToBeDownloaded()
for _, item := range *data {
url, _ := service.Download(item.FileURL, item.Title, item.Podcast.Title)
service.SetPodcastItemAsDownloaded(item.ID, url)
}
if err == nil {
c.JSON(200, data)
} else {
c.JSON(http.StatusInternalServerError, err.Error())
}
})
r.GET("/", func(c *gin.Context) {
//var podcasts []db.Podcast
podcasts := service.GetAllPodcasts()
@ -81,6 +54,7 @@ func main() {
_, err = service.AddPodcast(addPodcastData.Url)
if err == nil {
go service.RefreshEpisodes()
c.Redirect(http.StatusFound, "/")
} else {
@ -108,13 +82,13 @@ func intiCron() {
checkFrequency = 10
log.Print(err)
}
gocron.Every(uint64(checkFrequency)).Hours().Do(service.DownloadMissingEpisodes)
gocron.Every(uint64(checkFrequency)).Hours().Do(service.RefreshEpisodes)
//gocron.Every(uint64(checkFrequency)).Minutes().Do(service.DownloadMissingEpisodes)
gocron.Every(uint64(checkFrequency)).Minutes().Do(service.RefreshEpisodes)
<-gocron.Start()
}
func assetEnv() {
log.Println("Config Dir: ", os.Getenv("CONFIG"))
log.Println("Assets Dir: ", os.Getenv("DATA"))
log.Println("Check Frequency (hrs): ", os.Getenv("CHECK_FREQUENCY"))
log.Println("Check Frequency (mins): ", os.Getenv("CHECK_FREQUENCY"))
}

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"strconv"
"time"
@ -61,7 +60,7 @@ func AddPodcastItems(podcast *db.Podcast) error {
fmt.Println("Creating: " + podcast.ID)
data, err := FetchURL(podcast.URL)
if err != nil {
log.Fatal(err)
//log.Fatal(err)
return err
}
p := bluemonday.StripTagsPolicy()
@ -109,7 +108,6 @@ func DownloadMissingEpisodes() error {
url, _ := Download(item.FileURL, item.Title, item.Podcast.Title)
SetPodcastItemAsDownloaded(item.ID, url)
return nil
}
return nil
}
@ -125,6 +123,7 @@ func RefreshEpisodes() error {
AddPodcastItems(&item)
}
go DownloadMissingEpisodes()
return nil
}

Loading…
Cancel
Save