feat: 数据迁移新增实时日志&数据库游标遍历查询问题修复

This commit is contained in:
meilin.huang
2024-03-28 22:20:39 +08:00
parent 5e4793433b
commit d1d372e1bf
31 changed files with 477 additions and 344 deletions

View File

@@ -1,18 +1,14 @@
package api
import (
"context"
"fmt"
"mayfly-go/internal/db/api/form"
"mayfly-go/internal/db/api/vo"
"mayfly-go/internal/db/application"
"mayfly-go/internal/db/domain/entity"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/logx"
"mayfly-go/pkg/req"
"strconv"
"strings"
"time"
)
type DbTransferTask struct {
@@ -26,13 +22,6 @@ func (d *DbTransferTask) Tasks(rc *req.Ctx) {
rc.ResData = res
}
func (d *DbTransferTask) Logs(rc *req.Ctx) {
queryCond, page := req.BindQueryAndPage[*entity.DbTransferLogQuery](rc, new(entity.DbTransferLogQuery))
res, err := d.DbTransferTask.GetTaskLogList(queryCond, page, new([]vo.DbTransferLogListVO))
biz.ErrIsNil(err)
rc.ResData = res
}
func (d *DbTransferTask) SaveTask(rc *req.Ctx) {
reqForm := &form.DbTransferTaskForm{}
task := req.BindJsonAndCopyTo[*entity.DbTransferTask](rc, reqForm, new(entity.DbTransferTask))
@@ -54,34 +43,9 @@ func (d *DbTransferTask) DeleteTask(rc *req.Ctx) {
}
func (d *DbTransferTask) Run(rc *req.Ctx) {
start := time.Now()
taskId := d.changeState(rc, entity.DbTransferTaskRunStateRunning)
go d.DbTransferTask.Run(taskId, func(msg string, err error) {
// 修改状态为停止
if err != nil {
logx.Error(msg, err)
} else {
logx.Info(fmt.Sprintf("执行迁移完成,%s, 耗时:%v", msg, time.Since(start)))
}
// 修改任务状态
task := new(entity.DbTransferTask)
task.Id = taskId
task.RunningState = entity.DbTransferTaskRunStateStop
biz.ErrIsNil(d.DbTransferTask.UpdateById(context.Background(), task))
})
go d.DbTransferTask.Run(rc.MetaCtx, uint64(rc.PathParamInt("taskId")))
}
func (d *DbTransferTask) Stop(rc *req.Ctx) {
taskId := d.changeState(rc, entity.DbTransferTaskRunStateStop)
d.DbTransferTask.Stop(taskId)
}
func (d *DbTransferTask) changeState(rc *req.Ctx, RunningState int) uint64 {
reqForm := &form.DbTransferTaskStatusForm{RunningState: RunningState}
task := req.BindJsonAndCopyTo[*entity.DbTransferTask](rc, reqForm, new(entity.DbTransferTask))
biz.ErrIsNil(d.DbTransferTask.UpdateById(rc.MetaCtx, task))
// 记录请求日志
rc.ReqParam = reqForm
return task.Id
biz.ErrIsNil(d.DbTransferTask.Stop(rc.MetaCtx, uint64(rc.PathParamInt("taskId"))))
}