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,33 +60,44 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
return
}
for _, task := range tasks {
_task := apiModel.Task{
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,
}
taskResults := make([]apiModel.Task, len(tasks))
var wg sync.WaitGroup
status, submittedAt, err := s.GetTaskResult(_task.Daily, _task.TaskId.(int), userId)
if err != nil {
log.WithError(err).Error("group check task")
return nil, err
}
_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)
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,
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)
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
}
......
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