Skip to content

Commit

Permalink
feat: 创建task流程优化 #217
Browse files Browse the repository at this point in the history
  • Loading branch information
flyy1012 committed May 14, 2024
1 parent 24a8d82 commit 82833ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/backend/booster/server/pkg/manager/normal/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type TaskBasicLayer interface {
// list task basic from cache, return a new pointer
ListTaskBasic(released bool, statusList ...engine.TaskStatusType) ([]*engine.TaskBasic, error)

// init task basic, create task basic table in database
InitTaskBasic(tb *engine.TaskBasic) error
// create task basic, create task basic table in database
CreateTaskBasic(tb *engine.TaskBasic) error

//insert task basic to cache first time
InsertTB(tb *engine.TaskBasic) error
Expand Down Expand Up @@ -243,8 +243,8 @@ func (tc *taskBasicLayer) ListTaskBasic(
return rl, nil
}

// InitTaskBasic create a task basic in databases.
func (tc *taskBasicLayer) InitTaskBasic(tb *engine.TaskBasic) error {
// CreateTaskBasic create a task basic in databases.
func (tc *taskBasicLayer) CreateTaskBasic(tb *engine.TaskBasic) error {
egn, err := tc.GetEngineByTypeName(tb.Client.EngineName)
if err != nil {
blog.Errorf("layer: try updating task basic(%s), get engine(%s) failed: %v", tb.ID, tb.Client.EngineName, err)
Expand Down Expand Up @@ -360,6 +360,7 @@ func (tc *taskBasicLayer) updateTaskBasic(tbRaw *engine.TaskBasic, new bool) err
// InsertTB create a new record of init task in cache, do not need to create in queue
func (tc *taskBasicLayer) InsertTB(tbRaw *engine.TaskBasic) error {
tb := engine.CopyTaskBasic(tbRaw)
blog.Infof("layer: going to insertTB(%s) status(%s) to cache", tb.ID, tb.Status.Status)
tc.tbmLock.Lock()
defer tc.tbmLock.Unlock()
if tb.Status.Status != engine.TaskStatusInit {
Expand All @@ -376,7 +377,7 @@ func (tc *taskBasicLayer) InsertTB(tbRaw *engine.TaskBasic) error {

// DeleteTB delete task from cache and queue if task exsited
func (tc *taskBasicLayer) DeleteTB(tb *engine.TaskBasic) {
blog.Debugf("layer: going to deleteTB(%s) status(%s) from cache and queue", tb.ID, tb.Status.Status)
blog.Infof("layer: going to deleteTB(%s) status(%s) from cache and queue", tb.ID, tb.Status.Status)
tc.tbmLock.Lock()
defer tc.tbmLock.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions src/backend/booster/server/pkg/manager/normal/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ func (m *manager) createTask(param *mgr.TaskCreateParam) (*engine.TaskBasic, err
return nil, err
}

if err = m.layer.InitTaskBasic(tb); err != nil {
blog.Errorf("manager: init task basic(%s) for project(%s) in engine(%s) failed: %v",
if err = m.layer.CreateTaskBasic(tb); err != nil {
blog.Errorf("manager: create task basic(%s) for project(%s) in engine(%s) failed: %v",
taskID, param.ProjectID, pb.EngineName.String(), err)
//insert task to db failed, delete task from cache directly
m.layer.DeleteTB(tb)
Expand Down

0 comments on commit 82833ce

Please sign in to comment.