From 2895287d45bd7c6697109bd7a18892df2f6e4a23 Mon Sep 17 00:00:00 2001 From: hetao92 <18328704+hetao92@users.noreply.github.com> Date: Thu, 9 Mar 2023 07:09:29 +0000 Subject: [PATCH] mod: code review --- server/api/studio/internal/service/import.go | 3 +-- server/api/studio/internal/service/importer/importer.go | 6 ++++-- server/api/studio/internal/service/importer/taskmgr.go | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/server/api/studio/internal/service/import.go b/server/api/studio/internal/service/import.go index 45deaa2d..36a2545a 100644 --- a/server/api/studio/internal/service/import.go +++ b/server/api/studio/internal/service/import.go @@ -15,7 +15,6 @@ import ( "github.com/vesoft-inc/go-pkg/middleware" "github.com/vesoft-inc/nebula-importer/v4/pkg/config" - configbase "github.com/vesoft-inc/nebula-importer/v4/pkg/config/base" configv3 "github.com/vesoft-inc/nebula-importer/v4/pkg/config/v3" "github.com/vesoft-inc/nebula-studio/server/api/studio/internal/service/importer" "github.com/vesoft-inc/nebula-studio/server/api/studio/internal/svc" @@ -63,7 +62,7 @@ func NewImportService(ctx context.Context, svcCtx *svc.ServiceContext) ImportSer svcCtx: svcCtx, } } -func updateConfig(conf configbase.Configurator, taskDir, uploadDir string) { +func updateConfig(conf config.Configurator, taskDir, uploadDir string) { confv3 := conf.(*configv3.Config) if confv3.Log == nil { confv3.Log = &config.Log{} diff --git a/server/api/studio/internal/service/importer/importer.go b/server/api/studio/internal/service/importer/importer.go index 75e1e877..75ff0479 100644 --- a/server/api/studio/internal/service/importer/importer.go +++ b/server/api/studio/internal/service/importer/importer.go @@ -64,8 +64,10 @@ func StartImport(taskID int) (err error) { GetTaskMgr().AbortTask(taskID) return } - task.TaskInfo.TaskStatus = StatusFinished.String() - GetTaskMgr().FinishTask(taskID) + if task.TaskInfo.TaskStatus == StatusProcessing.String() { + task.TaskInfo.TaskStatus = StatusFinished.String() + GetTaskMgr().FinishTask(taskID) + } signal <- struct{}{} }() return nil diff --git a/server/api/studio/internal/service/importer/taskmgr.go b/server/api/studio/internal/service/importer/taskmgr.go index e20121f8..d3824e06 100644 --- a/server/api/studio/internal/service/importer/taskmgr.go +++ b/server/api/studio/internal/service/importer/taskmgr.go @@ -7,7 +7,7 @@ import ( "strconv" "sync" - importConfig "github.com/vesoft-inc/nebula-importer/v4/pkg/config" + importconfig "github.com/vesoft-inc/nebula-importer/v4/pkg/config" configv3 "github.com/vesoft-inc/nebula-importer/v4/pkg/config/v3" db "github.com/vesoft-inc/nebula-studio/server/api/studio/internal/model" "github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/ecode" @@ -46,7 +46,7 @@ func CreateNewTaskDir(rootDir string) (string, error) { func CreateConfigFile(taskdir string, cfgBytes []byte) error { fileName := "config.yaml" path := filepath.Join(taskdir, fileName) - config, _ := importConfig.FromBytes(cfgBytes) + config, _ := importconfig.FromBytes(cfgBytes) confv3 := config.(*configv3.Config) // erase user information @@ -65,7 +65,7 @@ func CreateConfigFile(taskdir string, cfgBytes []byte) error { return nil } -func (mgr *TaskMgr) NewTask(host string, user string, taskName string, cfg importConfig.Configurator) (*Task, int, error) { +func (mgr *TaskMgr) NewTask(host string, user string, taskName string, cfg importconfig.Configurator) (*Task, int, error) { mux.Lock() defer mux.Unlock() confv3 := cfg.(*configv3.Config) @@ -199,11 +199,11 @@ and then call FinishTask func (mgr *TaskMgr) StopTask(taskID int) error { if task, ok := mgr.getTaskFromMap(taskID); ok { manager := task.Client.Manager + task.TaskInfo.TaskStatus = StatusStoped.String() err := manager.Stop() if err != nil { return errors.New("stop task fail") } - task.TaskInfo.TaskStatus = StatusStoped.String() if err := mgr.FinishTask(taskID); err != nil { return ecode.WithErrorMessage(ecode.ErrInternalServer, err) }