- SyncStoresCategory

- TaskError for json output.
This commit is contained in:
gazebo
2018-10-27 16:12:00 +08:00
parent 970e8dc7b2
commit eac24b9a5a
8 changed files with 163 additions and 26 deletions

View File

@@ -43,7 +43,7 @@ func NewParallelConfig() *ParallelConfig {
return &ParallelConfig{
ParallelCount: DefParallelCount,
BatchSize: 1,
IsContinueWhenError: false,
IsContinueWhenError: true,
ResultHandler: nil,
}
}
@@ -127,7 +127,7 @@ func (task *ParallelTask) Run() {
goto end
}
task.locker.Lock()
task.DetailErrList = append(task.DetailErrList, err)
task.DetailErrList = append(task.DetailErrList, NewTaskError(err))
task.locker.Unlock()
}
}
@@ -175,7 +175,7 @@ func (task *ParallelTask) Run() {
task.Status = TaskStatusFinished
}
}
task.Err = taskErr
task.Err = NewTaskError(taskErr)
task.Result = taskResult
task.TerminatedAt = time.Now()
task.locker.Unlock()

View File

@@ -46,7 +46,7 @@ func (task *SeqTask) Run() {
break
}
task.locker.Lock()
task.DetailErrList = append(task.DetailErrList, err)
task.DetailErrList = append(task.DetailErrList, NewTaskError(err))
task.locker.Unlock()
} else if result != nil {
taskResult = append(taskResult, utils.Interface2Slice(result)...)
@@ -64,7 +64,7 @@ func (task *SeqTask) Run() {
task.Status = TaskStatusFinished
}
}
task.Err = taskErr
task.Err = NewTaskError(taskErr)
task.Result = taskResult
task.TerminatedAt = time.Now()
task.locker.Unlock()

View File

@@ -43,6 +43,20 @@ type ITask interface {
json.Marshaler
}
type TaskError struct {
error
}
func (t *TaskError) MarshalJSON() ([]byte, error) {
return json.Marshal(t.Error())
}
func NewTaskError(err error) *TaskError {
return &TaskError{
err,
}
}
type BaseTask struct {
Name string `json:"name"`
ID string `json:"id"`
@@ -61,10 +75,11 @@ type BaseTask struct {
FailedJobCount int `json:"failedJobCount"`
Status int `json:"status"`
Result []interface{} `json:"result"`
Err error `json:"err"`
Children TaskList `json:"children"`
DetailErrList []error `json:"detailErrList"`
Result []interface{} `json:"result"`
Children TaskList `json:"children"`
Err error `json:"err"`
DetailErrList []error `json:"detailErrList"`
finishChan chan int
C <-chan int `json:"-"`

View File

@@ -0,0 +1,14 @@
package tasksch
import (
"errors"
"fmt"
"testing"
"git.rosy.net.cn/baseapi/utils"
)
func TestTaskError(t *testing.T) {
err := NewTaskError(errors.New("hello"))
fmt.Println(utils.Format4Output(err, false))
}