chore: updates

This commit is contained in:
Simon Ding
2024-08-11 22:06:54 +08:00
parent 620f085ca5
commit 349e394e8e
3 changed files with 19 additions and 11 deletions

View File

@@ -36,14 +36,21 @@ func (c *Client) mustAddCron(spec string, cmd func()) {
func (c *Client) checkTasks() {
log.Debug("begin check tasks...")
for id, t := range c.tasks {
r := c.db.GetHistory(id)
if !t.Exists() {
log.Infof("task no longer exists: %v", id)
if r.Status == history.StatusRunning || r.Status == history.StatusUploading {
log.Warnf("task is running but no longer available in download client, mark as fail, task name: %s", r.SourceTitle)
c.db.SetHistoryStatus(id, history.StatusFail)
}
delete(c.tasks, id)
continue
}
log.Infof("task (%s) percentage done: %d%%", t.Name(), t.Progress())
if t.Progress() == 100 {
r := c.db.GetHistory(id)
if r.Status == history.StatusSuccess {
//task already success, check seed ratio
torrent := c.tasks[id]

View File

@@ -184,20 +184,21 @@ func searchWithTorznab(db *db.Client, queries ...string) []torznab.Result {
if tor.Disabled {
continue
}
wg.Add(1)
go func() {
log.Debugf("search torznab %v with %v", tor.Name, queries)
defer wg.Done()
for _, q := range queries {
for _, q := range queries {
wg.Add(1)
go func() {
log.Debugf("search torznab %v with %v", tor.Name, queries)
defer wg.Done()
resp, err := torznab.Search(tor, q)
if err != nil {
log.Warnf("search %s with query %s error: %v", tor.Name, q, err)
continue
return
}
resChan <- resp
}
}()
}()
}
}
go func() {
wg.Wait()