imbajin commented on code in PR #336:
URL:
https://github.com/apache/incubator-hugegraph-computer/pull/336#discussion_r2422717374
##########
vermeer/apps/master/bl/task_creator.go:
##########
@@ -99,6 +99,28 @@ func (bc *baseCreator) NewTaskInfo(graphName string, params
map[string]string, t
return task, nil
}
+func (bc *baseCreator) CopyTaskInfo(src *structure.TaskInfo)
(*structure.TaskInfo, error) {
Review Comment:
**Poor error handling in copy operation**
When copying task info, if any error occurs after task creation, the
partially created task is left in the system without cleanup.
**Suggested fix:**
```go
func (bc *baseCreator) CopyTaskInfo(src *structure.TaskInfo)
(*structure.TaskInfo, error) {
if src == nil {
return nil, fmt.Errorf("the argument 'src' should not be nil")
}
task, err := taskMgr.CreateTask(src.SpaceName, src.Type, 0)
if err != nil {
return nil, err
}
// Ensure cleanup on error
success := false
defer func() {
if !success {
if cleanupErr := taskMgr.RemoveTask(task.ID); cleanupErr != nil {
logrus.Errorf("failed to cleanup task %d after copy error:
%v", task.ID, cleanupErr)
}
}
}()
task.CreateType = structure.TaskCreateAsync
task.GraphName = src.GraphName
task.CreateUser = src.CreateUser
task.Params = src.Params
task.CronExpr = "" // clear cron expression for the new task
task.Priority = src.Priority
task.Preorders = src.Preorders
task.Exclusive = src.Exclusive
success = true
return task, nil
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]