Commit b1097bf5 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

update parallel query

parent 928a987b
......@@ -189,6 +189,4 @@ func submitTask(c *gin.Context) {
return
}
c.JSON(200, withSuccess(gin.H{}))
return
}
package service
import (
"sync"
"taskcenter/constant"
apiModel "taskcenter/model/api"
dbModel "taskcenter/model/db"
......@@ -59,7 +60,14 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
return
}
for _, task := range tasks {
taskResults := make([]apiModel.Task, len(tasks))
var wg sync.WaitGroup
for i := range tasks {
wg.Add(1)
go func(idx int) {
defer wg.Done()
task := tasks[idx]
_task := apiModel.Task{
TaskId: task.Id,
Platform: task.Platform,
......@@ -77,15 +85,19 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
status, submittedAt, err := s.GetTaskResult(_task.Daily, _task.TaskId.(int), userId)
if err != nil {
log.WithError(err).Error("group check task")
return nil, err
return
}
_task.Status = status
if status == constant.TaskHistoryStatusRetry {
_task.Msg = "The task is not completed, please try again."
}
_task.SubmitTimestamp = int(submittedAt.Unix())
resp.Tasks = append(resp.Tasks, _task)
taskResults[idx] = _task
}(i)
}
wg.Wait()
resp.Tasks = taskResults
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment