diff --git a/entity/fs_file_info.go b/entity/fs_file_info.go index 1376150..0fbf79f 100644 --- a/entity/fs_file_info.go +++ b/entity/fs_file_info.go @@ -2,6 +2,8 @@ package entity import ( "github.com/crawlab-team/crawlab-core/interfaces" + "os" + "time" ) type FsFileInfo struct { @@ -9,10 +11,11 @@ type FsFileInfo struct { Path string `json:"path"` // file path FullPath string `json:"full_path"` // file full path Extension string `json:"extension"` // file extension - Md5 string `json:"md5"` // MD5 hash IsDir bool `json:"is_dir"` // whether it is directory FileSize int64 `json:"file_size"` // file size (bytes) Children []interfaces.FsFileInfo `json:"children"` // children for sub-directory + ModTime time.Time `json:"mod_time"` // modification time + Mode os.FileMode `json:"mode"` // file mode } func (f *FsFileInfo) GetName() string { @@ -31,10 +34,6 @@ func (f *FsFileInfo) GetExtension() string { return f.Extension } -func (f *FsFileInfo) GetMd5() string { - return f.Md5 -} - func (f *FsFileInfo) GetIsDir() bool { return f.IsDir } @@ -43,6 +42,14 @@ func (f *FsFileInfo) GetFileSize() int64 { return f.FileSize } +func (f *FsFileInfo) GetModTime() time.Time { + return f.ModTime +} + +func (f *FsFileInfo) GetMode() os.FileMode { + return f.Mode +} + func (f *FsFileInfo) GetChildren() []interfaces.FsFileInfo { return f.Children } diff --git a/fs/service_v2.go b/fs/service_v2.go index 5e2ee60..f733fdb 100644 --- a/fs/service_v2.go +++ b/fs/service_v2.go @@ -43,9 +43,10 @@ func (svc *ServiceV2) List(path string) (files []interfaces.FsFileInfo, err erro Path: filepath.ToSlash(relPath), FullPath: p, Extension: filepath.Ext(p), - Md5: "", IsDir: info.IsDir(), FileSize: info.Size(), + ModTime: info.ModTime(), + Mode: info.Mode(), Children: nil, } @@ -90,9 +91,10 @@ func (svc *ServiceV2) GetFileInfo(path string) (file interfaces.FsFileInfo, err Path: path, FullPath: filepath.Join(svc.rootPath, path), Extension: filepath.Ext(path), - Md5: "", IsDir: f.IsDir(), FileSize: f.Size(), + ModTime: f.ModTime(), + Mode: f.Mode(), Children: nil, }, nil } diff --git a/interfaces/fs_file_info.go b/interfaces/fs_file_info.go index 9b604ae..ee65109 100644 --- a/interfaces/fs_file_info.go +++ b/interfaces/fs_file_info.go @@ -1,12 +1,18 @@ package interfaces +import ( + "os" + "time" +) + type FsFileInfo interface { GetName() string GetPath() string GetFullPath() string GetExtension() string - GetMd5() string GetIsDir() bool GetFileSize() int64 + GetModTime() time.Time + GetMode() os.FileMode GetChildren() []FsFileInfo } diff --git a/task/handler/service.go b/task/handler/service.go index 3a68221..763b98a 100644 --- a/task/handler/service.go +++ b/task/handler/service.go @@ -3,10 +3,11 @@ package handler import ( "context" "encoding/json" + "errors" "github.com/apex/log" config2 "github.com/crawlab-team/crawlab-core/config" "github.com/crawlab-team/crawlab-core/constants" - "github.com/crawlab-team/crawlab-core/errors" + errors2 "github.com/crawlab-team/crawlab-core/errors" client2 "github.com/crawlab-team/crawlab-core/grpc/client" "github.com/crawlab-team/crawlab-core/interfaces" "github.com/crawlab-team/crawlab-core/models/client" @@ -311,13 +312,13 @@ func (svc *Service) getRunner(taskId primitive.ObjectID) (r interfaces.TaskRunne log.Debugf("[TaskHandlerService] getRunner: taskId[%v]", taskId) v, ok := svc.runners.Load(taskId) if !ok { - return nil, trace.TraceError(errors.ErrorTaskNotExists) + return nil, trace.TraceError(errors2.ErrorTaskNotExists) } switch v.(type) { case interfaces.TaskRunner: r = v.(interfaces.TaskRunner) default: - return nil, trace.TraceError(errors.ErrorModelInvalidType) + return nil, trace.TraceError(errors2.ErrorModelInvalidType) } return r, nil } @@ -405,7 +406,7 @@ func (svc *Service) run(taskId primitive.ObjectID) (err error) { // attempt to get runner from pool _, ok := svc.runners.Load(taskId) if ok { - return trace.TraceError(errors.ErrorTaskAlreadyExists) + return trace.TraceError(errors2.ErrorTaskAlreadyExists) } // create a new task runner @@ -430,10 +431,10 @@ func (svc *Service) run(taskId primitive.ObjectID) (err error) { // run task process (blocking) // error or finish after task runner ends if err := r.Run(); err != nil { - switch err { - case constants.ErrTaskError: + switch { + case errors.Is(err, constants.ErrTaskError): log.Errorf("task[%s] finished with error: %v", r.GetTaskId().Hex(), err) - case constants.ErrTaskCancelled: + case errors.Is(err, constants.ErrTaskCancelled): log.Errorf("task[%s] cancelled", r.GetTaskId().Hex()) default: log.Errorf("task[%s] finished with unknown error: %v", r.GetTaskId().Hex(), err)