-
Notifications
You must be signed in to change notification settings - Fork 208
Task re execute #3152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Task re execute #3152
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
55e43b6
feat(workflow): implement task re-execution logic and validation checks
iwanghc 4e86799
feat(storage): add methods for retrieving task details and executing …
iwanghc faa8f17
feat(task): enhance addTask method to accept execSqlIds and add new A…
iwanghc c80ccf3
test: add mock expectation for execute_sql_detail query in action exe…
iwanghc f7178ef
fix: handle error from GetExecSqlsByTaskIdAndStatus in action execution
iwanghc 29e7c64
remove: Re-execution does not require im notification and unused chan
iwanghc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strconv" | ||
| "sync" | ||
|
|
||
| "github.com/actiontech/sqle/sqle/common" | ||
| "github.com/actiontech/sqle/sqle/dms" | ||
| "github.com/actiontech/sqle/sqle/errors" | ||
| "github.com/actiontech/sqle/sqle/log" | ||
| "github.com/actiontech/sqle/sqle/model" | ||
| "github.com/actiontech/sqle/sqle/notification" | ||
| ) | ||
|
|
||
| func ReExecuteTaskSQLs(workflow *model.Workflow, task *model.Task, execSqlIds []uint, user *model.User) error { | ||
| s := model.GetStorage() | ||
| l := log.NewEntry() | ||
|
|
||
| instance, exist, err := dms.GetInstancesById(context.Background(), fmt.Sprintf("%d", task.InstanceId)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if !exist { | ||
| return errors.New(errors.DataNotExist, fmt.Errorf("instance is not exist. instanceId=%v", task.InstanceId)) | ||
| } | ||
| task.Instance = instance | ||
| if task.Instance == nil { | ||
| return errors.New(errors.DataNotExist, fmt.Errorf("instance is not exist")) | ||
| } | ||
|
|
||
| // if instance is not connectable, exec sql must be failed; | ||
| // commit action unable to retry, so don't to exec it. | ||
| if err = common.CheckInstanceIsConnectable(task.Instance); err != nil { | ||
| return errors.New(errors.ConnectRemoteDatabaseError, err) | ||
| } | ||
|
|
||
| needExecTaskRecords := make([]*model.WorkflowInstanceRecord, 0, len(workflow.Record.InstanceRecords)) | ||
| // update workflow | ||
| for _, inst := range workflow.Record.InstanceRecords { | ||
| if inst.TaskId != task.ID { | ||
| continue | ||
| } | ||
| inst.IsSQLExecuted = true | ||
| inst.ExecutionUserId = user.GetIDStr() | ||
| needExecTaskRecords = append(needExecTaskRecords, inst) | ||
| } | ||
|
|
||
| workflow.Record.Status = model.WorkflowStatusExecuting | ||
| workflow.Record.CurrentWorkflowStepId = 0 | ||
|
|
||
| err = s.UpdateWorkflowExecInstanceRecordForReExecute(workflow, needExecTaskRecords) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| var lock sync.Mutex | ||
| go func() { | ||
| sqledServer := GetSqled() | ||
| task, err := sqledServer.AddTaskWaitResultWithSQLIds(string(workflow.ProjectId), strconv.Itoa(int(task.ID)), execSqlIds, ActionTypeExecute) | ||
| { | ||
| lock.Lock() | ||
| updateStatus(s, workflow, l, nil) | ||
| lock.Unlock() | ||
| } | ||
| if err != nil || task.Status == model.TaskStatusExecuteFailed { | ||
| go notification.NotifyWorkflow(string(workflow.ProjectId), workflow.WorkflowId, notification.WorkflowNotifyTypeExecuteFail) | ||
| } else { | ||
| go notification.NotifyWorkflow(string(workflow.ProjectId), workflow.WorkflowId, notification.WorkflowNotifyTypeExecuteSuccess) | ||
| } | ||
|
|
||
| }() | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.