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,33 +60,44 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G ...@@ -59,33 +60,44 @@ 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))
_task := apiModel.Task{ var wg sync.WaitGroup
TaskId: task.Id,
Platform: task.Platform,
Action: task.Action,
Url: task.Url,
Description: task.Description,
Reward: task.Reward,
Start: task.Start,
End: task.End,
Daily: task.Daily,
TweetId: task.TweetId,
Enable: task.Enable,
}
status, submittedAt, err := s.GetTaskResult(_task.Daily, _task.TaskId.(int), userId) for i := range tasks {
if err != nil { wg.Add(1)
log.WithError(err).Error("group check task") go func(idx int) {
return nil, err defer wg.Done()
} task := tasks[idx]
_task.Status = status _task := apiModel.Task{
if status == constant.TaskHistoryStatusRetry { TaskId: task.Id,
_task.Msg = "The task is not completed, please try again." Platform: task.Platform,
} Action: task.Action,
_task.SubmitTimestamp = int(submittedAt.Unix()) Url: task.Url,
resp.Tasks = append(resp.Tasks, _task) Description: task.Description,
Reward: task.Reward,
Start: task.Start,
End: task.End,
Daily: task.Daily,
TweetId: task.TweetId,
Enable: task.Enable,
}
status, submittedAt, err := s.GetTaskResult(_task.Daily, _task.TaskId.(int), userId)
if err != nil {
log.WithError(err).Error("group check task")
return
}
_task.Status = status
if status == constant.TaskHistoryStatusRetry {
_task.Msg = "The task is not completed, please try again."
}
_task.SubmitTimestamp = int(submittedAt.Unix())
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