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

update retry task

parent 57ee0024
...@@ -172,6 +172,11 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool) (ex ...@@ -172,6 +172,11 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool) (ex
return false, err return false, err
} }
} }
// 已存在,更新updated_at字段
if err == nil {
return true, tx.Model(&dbModel.TaskHistory{}).Where("task_id = ? and user_id = ?", taskId, userId).Update("updated_at", time.Now()).Error
}
return err == nil, err return err == nil, err
} }
...@@ -187,6 +192,10 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool) (ex ...@@ -187,6 +192,10 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool) (ex
return false, err return false, err
} }
} }
// 已存在,更新updated_at字段
if err == nil {
return true, tx.Model(&dbModel.TaskHistory{}).Where("task_id = ? and user_id = ? and created_at >= ?", taskId, userId, time.Now().UTC().Truncate(24*time.Hour)).Update("updated_at", time.Now()).Error
}
return err == nil, err return err == nil, err
} }
...@@ -198,7 +207,7 @@ func (d *Dao) UpdateTaskHistory(id int, status string) (err error) { ...@@ -198,7 +207,7 @@ func (d *Dao) UpdateTaskHistory(id int, status string) (err error) {
func (d *Dao) GetUnprocessedTasks() (tasks []*dbModel.TaskHistory, err error) { func (d *Dao) GetUnprocessedTasks() (tasks []*dbModel.TaskHistory, err error) {
// twitter延迟3分钟,其余延迟1分钟 // twitter延迟3分钟,其余延迟1分钟
sql := fmt.Sprintf( sql := fmt.Sprintf(
`SELECT TH.* FROM %s AS TH JOIN %s AS T ON TH.task_id = T.id WHERE TH.status = ? AND ((T.platform = ? AND TH.created_at <= NOW() - INTERVAL '3 minutes') OR (T.platform != ? AND TH.created_at <= NOW() - INTERVAL '1 minutes'))`, `SELECT TH.* FROM %s AS TH JOIN %s AS T ON TH.task_id = T.id WHERE TH.status = ? AND ((T.platform = ? AND TH.updated_at <= NOW() - INTERVAL '3 minutes') OR (T.platform != ? AND TH.updated_at <= NOW() - INTERVAL '1 minutes'))`,
(&dbModel.TaskHistory{}).TableName(), (&dbModel.Task{}).TableName(), (&dbModel.TaskHistory{}).TableName(), (&dbModel.Task{}).TableName(),
) )
// ignore log // ignore log
......
...@@ -8,7 +8,7 @@ services: ...@@ -8,7 +8,7 @@ services:
pull_policy: always pull_policy: always
container_name: taskcenter-api container_name: taskcenter-api
ports: ports:
- "16670:8080" - "30002:8080"
volumes: volumes:
- ./conf/taskcenter/config.toml:/config.toml - ./conf/taskcenter/config.toml:/config.toml
- ./conf/taskcenter/db.crt:/app/db.crt - ./conf/taskcenter/db.crt:/app/db.crt
......
...@@ -86,6 +86,7 @@ type TaskHistory struct { ...@@ -86,6 +86,7 @@ type TaskHistory struct {
RewardTxHash string `gorm:"type:text;not null;index;comment:发放奖励的txHash"` RewardTxHash string `gorm:"type:text;not null;index;comment:发放奖励的txHash"`
Status string `gorm:"type:text;not null;comment:任务状态"` Status string `gorm:"type:text;not null;comment:任务状态"`
CreatedAt time.Time `gorm:"index"` CreatedAt time.Time `gorm:"index"`
UpdatedAt time.Time `gorm:"index"`
gorm.Model gorm.Model
} }
......
...@@ -50,16 +50,27 @@ func submitTask(c *gin.Context) { ...@@ -50,16 +50,27 @@ func submitTask(c *gin.Context) {
return return
} }
exist, err := srv.SubmitTask(taskId, userId, task.Daily) status, err := srv.GetTaskResult(taskId, userId)
if err != nil { if err != nil {
c.JSON(200, withError(constant.InternalError)) c.JSON(200, withError(constant.InternalError))
return return
} }
if exist { if status == constant.TaskHistoryStatusPending {
c.JSON(200, withError("task already submitted")) c.JSON(200, withError("task already submitted"))
return return
} }
if status == constant.TaskHistoryStatusSuccess {
c.JSON(200, withError("task already done"))
return
}
_, err = srv.SubmitTask(taskId, userId, task.Daily)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
}
c.JSON(200, withSuccess(gin.H{})) c.JSON(200, withSuccess(gin.H{}))
} }
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