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

update parallel query

parent 928a987b
...@@ -189,6 +189,4 @@ func submitTask(c *gin.Context) { ...@@ -189,6 +189,4 @@ func submitTask(c *gin.Context) {
return return
} }
c.JSON(200, withSuccess(gin.H{})) c.JSON(200, withSuccess(gin.H{}))
return
} }
package service package service
import ( import (
"sync"
"taskcenter/constant" "taskcenter/constant"
apiModel "taskcenter/model/api" apiModel "taskcenter/model/api"
dbModel "taskcenter/model/db" dbModel "taskcenter/model/db"
...@@ -59,7 +60,14 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G ...@@ -59,7 +60,14 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
return 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{ _task := apiModel.Task{
TaskId: task.Id, TaskId: task.Id,
Platform: task.Platform, Platform: task.Platform,
...@@ -77,15 +85,19 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G ...@@ -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) status, submittedAt, err := s.GetTaskResult(_task.Daily, _task.TaskId.(int), userId)
if err != nil { if err != nil {
log.WithError(err).Error("group check task") log.WithError(err).Error("group check task")
return nil, err return
} }
_task.Status = status _task.Status = status
if status == constant.TaskHistoryStatusRetry { if status == constant.TaskHistoryStatusRetry {
_task.Msg = "The task is not completed, please try again." _task.Msg = "The task is not completed, please try again."
} }
_task.SubmitTimestamp = int(submittedAt.Unix()) _task.SubmitTimestamp = int(submittedAt.Unix())
resp.Tasks = append(resp.Tasks, _task) taskResults[idx] = _task
}(i)
} }
wg.Wait()
resp.Tasks = taskResults
return 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