feat: task reloading

This commit is contained in:
Simon Ding
2024-07-12 15:21:33 +08:00
parent 55966b8115
commit 799884f73c
4 changed files with 81 additions and 17 deletions

View File

@@ -78,7 +78,11 @@ type searchAndDownloadIn struct {
func (s *Server) searchAndDownload(seriesId, seasonNum, episodeNum int) (*string, error) {
tr := s.db.GetTransmission()
trc, err := transmission.NewClient(tr.URL, tr.User, tr.Password)
trc, err := transmission.NewClient(transmission.Config{
URL: tr.URL,
User: tr.User,
Password: tr.Password,
})
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}

View File

@@ -5,6 +5,7 @@ import (
"polaris/log"
"polaris/pkg"
"polaris/pkg/tmdb"
"polaris/pkg/transmission"
"polaris/ui"
"github.com/gin-contrib/static"
@@ -35,6 +36,7 @@ type Server struct {
func (s *Server) Serve() error {
s.scheduler()
s.reloadTasks()
//st, _ := fs.Sub(ui.Web, "build/web")
s.r.Use(static.Serve("/", static.EmbedFolder(ui.Web, "build/web")))
@@ -99,3 +101,20 @@ func (s *Server) MustTMDB() *tmdb.Client {
}
return t
}
func (s *Server) reloadTasks() {
runningTasks := s.db.GetRunningHistories()
if len(runningTasks) == 0 {
return
}
for _, t := range runningTasks {
log.Infof("reloading task: %s", t.SourceTitle)
torrent, err := transmission.ReloadTorrent(t.Saved)
if err != nil {
log.Errorf("relaod task %s failed: %v", t.SourceTitle, err)
continue
}
s.tasks[t.ID] = torrent
}
}