feat: episode status

This commit is contained in:
Simon Ding
2024-07-15 14:41:49 +08:00
parent 68897e85f9
commit 9a3a4addeb
15 changed files with 288 additions and 50 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"polaris/db"
"polaris/ent"
"polaris/ent/episode"
"polaris/ent/history"
"polaris/log"
"polaris/pkg/torznab"
@@ -123,6 +124,7 @@ func (s *Server) searchAndDownload(seriesId, seasonNum, episodeNum int) (*string
Status: history.StatusRunning,
Saved: torrent.Save(),
})
s.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
if err != nil {
return nil, errors.Wrap(err, "save record")
}

View File

@@ -3,6 +3,7 @@ package server
import (
"path/filepath"
"polaris/ent"
"polaris/ent/episode"
"polaris/ent/history"
storage1 "polaris/ent/storage"
"polaris/log"
@@ -17,7 +18,7 @@ import (
func (s *Server) scheduler() {
s.mustAddCron("@every 1m", s.checkTasks)
s.mustAddCron("@every 10m", s.checkAllFiles)
//s.mustAddCron("@every 1h", s.checkAllFiles)
s.cron.Start()
}
@@ -59,10 +60,13 @@ func (s *Server) moveCompletedTask(id int) (err error) {
defer func () {
if err != nil {
s.db.SetHistoryStatus(r.ID, history.StatusFail)
s.db.SetEpisodeStatus(r.EpisodeID, episode.StatusMissing)
} else {
torrent.Remove()
delete(s.tasks, r.ID)
s.db.SetHistoryStatus(r.ID, history.StatusSuccess)
s.db.SetEpisodeStatus(r.EpisodeID, episode.StatusDownloaded)
torrent.Remove()
}
}()