Skip to content

Commit

Permalink
Merge pull request #50 from qingfeng777/master
Browse files Browse the repository at this point in the history
[redis] exec begin at work
  • Loading branch information
qingfeng777 authored Jul 9, 2023
2 parents c5d8e92 + e7e9bce commit b6feed7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go/api/v1/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (taskApi *TaskApi) UpdateTask(ctx *gin.Context) {
}
fillSubTask(&taskParam, nil)

if err := task.UpdateTask(ctx, &taskParam.Task); err != nil {
if err := task.UpdateTask(ctx, &taskParam.Task, taskParam.Task.StartAtId); err != nil {
response.FailWithMessage(fmt.Sprintf("%s, update task failed :%s", f, err.Error()), ctx)
return
}
Expand Down
2 changes: 1 addition & 1 deletion go/service/auth/auth/auth_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (a Auth) AddTask(ctx context.Context, cluster string, db int, parentTaskID
}

// give auth by set status
func (a Auth) ExecTask(ctx context.Context, taskId int64, cluster, db string) error {
func (a Auth) ExecTask(ctx context.Context, startSubTaskId, taskId int64, cluster, db string) error {
a.Status = StatusPass
return authDao.UpdateAuth(&a)
}
Expand Down
21 changes: 16 additions & 5 deletions go/service/redis/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *RedisTask) AddTask(ctx context.Context, cluster string, db int, parentT
return 0, checkPass, tx.Commit().Error
}

func (r *RedisTask) ExecTask(ctx context.Context, taskId int64, cluster, db string) error {
func (r *RedisTask) ExecTask(ctx context.Context, startSubTaskId, taskId int64, cluster, db string) error {
tasks, err := redisTaskDao.ListRedisTaskByTaskID(GetDB(), taskId)
if err != nil {
return fmt.Errorf("while exec task, get task err: %v", err)
Expand All @@ -78,10 +78,21 @@ func (r *RedisTask) ExecTask(ctx context.Context, taskId int64, cluster, db stri
return err
}

// exec, // 假设都是独立的,更常见的场景。
// todo, get parent task, and set
// exec, 假设都是独立的,更常见的场景。
start := false
if startSubTaskId <= 0 {
start = true
}

var failed bool
for _, v := range tasks {
if v.ID == startSubTaskId {
start = true
}
if !start {
continue
}

resp, err := exec(ctx, v.Cmd, cluster, database)
if err != nil {
failed = true
Expand Down Expand Up @@ -109,8 +120,8 @@ func (r *RedisTask) ListTask(parentTaskID int64) (interface{}, error) {
}

var iTasks []task.SubTask
for _, v := range rTasks {
iTasks = append(iTasks, task.SubTask(&v))
for i := range rTasks {
iTasks = append(iTasks, task.SubTask(&rTasks[i]))
}
return iTasks, nil
}
Expand Down
11 changes: 6 additions & 5 deletions go/service/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ type Task struct {
Et int64 `json:"et" gorm:"column:et"`
Ft int64 `json:"ft" gorm:"column:ft"`

SubTask SubTask `json:"sub_task" gorm:"-"`
SubTasks []SubTask `json:"sub_tasks" gorm:"-"`
SubTask SubTask `json:"sub_task" gorm:"-"`
SubTasks []SubTask `json:"sub_tasks" gorm:"-"`
StartAtId int64 `json:"start_at_id" gorm:"-"`

StatusName string `json:"status_name" gorm:"-"`
Action string `json:"action" gorm:"-"`
Expand All @@ -49,7 +50,7 @@ type Task struct {
type SubTask interface {
AddTask(ctx context.Context, cluster string, db int, parentTaskID int64) (int64, bool, error)
//TODO, refactor, auth db on subtask, redis db on parent task;
ExecTask(ctx context.Context, taskId int64, cluster, db string) error
ExecTask(ctx context.Context, startSubTaskId, taskId int64, cluster, db string) error
UpdateTask(action string) error
ListTask(parentTaskID int64) (interface{}, error)
GetTask(id int64) (interface{}, error)
Expand Down Expand Up @@ -84,7 +85,7 @@ func AddTask(ctx context.Context, task *Task) (int64, error) {
return taskId, err
}

func UpdateTask(ctx context.Context, task *Task) error {
func UpdateTask(ctx context.Context, task *Task, startAtId int64) error {
// subtask is nil
var err error
if err = task.SubTask.UpdateTask(task.Action); err != nil {
Expand All @@ -106,7 +107,7 @@ func UpdateTask(ctx context.Context, task *Task) error {
return err
}
task.Status = Pass
task.SubTask.ExecTask(ctx, storeTask.ID, storeTask.Cluster, storeTask.Database)
task.SubTask.ExecTask(ctx, startAtId, storeTask.ID, storeTask.Cluster, storeTask.Database)
case ActionUpdate:
}

Expand Down
13 changes: 8 additions & 5 deletions web/src/view/redis/exec/exec.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@
<el-table-column prop="exec_info" width="200" label="执行信息"></el-table-column>
<el-table-column prop="cat_id" fixed="right" label="操作">
<template #default="scope">
<!-- <el-button
<el-button
icon="edit"
size="small"
type="text"
@click="onExecAt(scope.row)"
>此处开始</el-button> -->
>此处开始</el-button>
</template>
</el-table-column>
</el-table>
Expand Down Expand Up @@ -191,9 +191,12 @@ const onExec = async() => {
const onExecAt = async(row) => {
execVisible.value = false
let params = {
id: Number(rout.params.id),
exec_item: row,
action: 'beginAt'
task:{
id: Number(rout.params.id),
action: 'exec',
sub_task_type: 'redis',
start_at_id: row.id,
}
}
const res = await updateTask(params)
if (res.code === 0) {
Expand Down

0 comments on commit b6feed7

Please sign in to comment.