Skip to content

Commit

Permalink
feat: it is not allowed to execute workflow that have pre-workflow wa…
Browse files Browse the repository at this point in the history
…s not executed correctly
  • Loading branch information
winfredLIN committed Oct 9, 2024
1 parent ab7019e commit e77c201
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
39 changes: 38 additions & 1 deletion sqle/api/controller/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,14 @@ func ExecuteOneTaskOnWorkflowV2(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

executable, reason, err := sqlversion.CheckWorkflowExecutable(projectUid, workflowID)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
if !executable {
return controller.JSONBaseErrorReq(c, fmt.Errorf(reason))
}

isCan, err := v1.IsTaskCanExecute(s, taskIdStr)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
Expand Down Expand Up @@ -1027,6 +1035,14 @@ func UpdateWorkflowScheduleV2(c echo.Context) error {
return controller.JSONBaseErrorReq(c, v1.ErrWorkflowExecuteTimeIncorrect)
}

executable, reason, err := sqlversion.CheckWorkflowExecutable(projectUid, workflowId)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
if !executable {
return controller.JSONBaseErrorReq(c, fmt.Errorf(reason))
}

err = s.UpdateInstanceRecordSchedule(curTaskRecord, user.GetIDStr(), req.ScheduleTime)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
Expand Down Expand Up @@ -1074,8 +1090,17 @@ func ExecuteTasksOnWorkflowV2(c echo.Context) error {
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}

executable, reason, err := sqlversion.CheckWorkflowExecutable(projectUid, workflowId)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
if !executable {
return controller.JSONBaseErrorReq(c, fmt.Errorf(reason))
}

if err := v1.PrepareForWorkflowExecution(c, projectUid, workflow, user); err != nil {
return err
return controller.JSONBaseErrorReq(c, err)
}

_, err = server.ExecuteTasksProcess(workflow.WorkflowId, projectUid, user)
Expand Down Expand Up @@ -1268,11 +1293,23 @@ func convertWorkflowRecordToRes(workflow *model.Workflow, record *model.Workflow
tasksRes[i] = &WorkflowTaskItem{Id: inst.TaskId}
}

var err error
var executable bool
var reason string = fmt.Sprintf("the status of workflow is %v", record.Status)
if record.Status == model.WorkflowStatusWaitForExecution {
executable, reason, err = sqlversion.CheckWorkflowExecutable(string(workflow.ProjectId), workflow.WorkflowId)
if err != nil {
reason = err.Error()
}
}

return &WorkflowRecordResV2{
Tasks: tasksRes,
CurrentStepNumber: currentStepNum,
Status: record.Status,
Steps: steps,
Executable: executable,
ExecutableReason: reason,
}
}

Expand Down
8 changes: 8 additions & 0 deletions sqle/api/controller/v3/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/actiontech/sqle/sqle/dms"
"github.com/actiontech/sqle/sqle/errors"
"github.com/actiontech/sqle/sqle/model"
"github.com/actiontech/sqle/sqle/server/sqlversion"
"github.com/labstack/echo/v4"
)

Expand Down Expand Up @@ -54,6 +55,13 @@ func BatchCompleteWorkflowsV3(c echo.Context) error {
s := model.GetStorage()
workflows := make([]*model.Workflow, len(req.WorkflowList))
for i, completeWorkflow := range req.WorkflowList {
executable, reason, err := sqlversion.CheckWorkflowExecutable(projectUid, completeWorkflow.WorkflowID)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
if !executable {
return controller.JSONBaseErrorReq(c, fmt.Errorf(reason))
}
workflow, err := v2.CheckCanCompleteWorkflow(projectUid, completeWorkflow.WorkflowID)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
Expand Down
4 changes: 4 additions & 0 deletions sqle/server/sqlversion/sql_version_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ import (
func CheckInstanceInWorkflowCanAssociateToTheFirstStageOfVersion(versionID uint, instanceId []uint64) error {
return errors.New(errors.EnterpriseEditionFeatures, e.New("sql version is enterprise version feature"))
}

func CheckWorkflowExecutable(projectUid, workflowId string) (executable bool, reason string, err error) {
return true, "", nil
}

0 comments on commit e77c201

Please sign in to comment.