refactor: thread safe tasks

This commit is contained in:
Simon Ding
2025-04-08 14:01:32 +08:00
parent 9014f846be
commit 2bc71b0c66
5 changed files with 36 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ package server
import (
"fmt"
"polaris/engine"
"polaris/ent"
"polaris/ent/blacklist"
"polaris/ent/episode"
@@ -31,7 +32,8 @@ func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
a := Activity{
History: h,
}
for id, task := range s.core.GetTasks() {
tasks := s.core.GetTasks()
tasks.Range(func(id int, task *engine.Task) bool {
if h.ID == id && task.Exists() {
p, err := task.Progress()
if err != nil {
@@ -49,7 +51,9 @@ func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
a.UploadProgress = task.UploadProgresser()
}
}
}
return true
})
activities = append(activities, a)
}
} else {