- 特殊处理同步价格至平台出错,较大改动

This commit is contained in:
gazebo
2019-06-06 15:01:48 +08:00
parent 89451ede5f
commit a66d69a265
10 changed files with 214 additions and 66 deletions

View File

@@ -57,6 +57,8 @@ type ITask interface {
AddChild(task ITask) ITask
GetChildren() TaskList
SetParent(parentTask ITask)
GetOriginalErr() error
GetDetailErrList() []error
json.Marshaler
}
@@ -105,15 +107,17 @@ type BaseTask struct {
NoticeMsg string `json:"noticeMsg"`
Result []interface{} `json:"-"`
Children TaskList `json:"children"`
Err error `json:"err"`
Result []interface{} `json:"-"`
Children TaskList `json:"children"`
Err error `json:"err"`
OriginalErr error `json:"-"`
detailErrMsgList []string
finishChan chan struct{}
C <-chan struct{} `json:"-"`
params []interface{}
quitChan chan int
detailErrList []error
finishChan chan struct{}
C <-chan struct{} `json:"-"`
params []interface{}
quitChan chan int
locker sync.RWMutex
parent ITask
@@ -163,7 +167,7 @@ func (t *BaseTask) GetID() string {
func (t *BaseTask) GetResult(duration time.Duration) (retVal []interface{}, err error) {
if t.GetStatus() >= TaskStatusEndBegin {
return t.Result, t.Err
return t.Result, t.OriginalErr
}
if duration == 0 {
duration = time.Hour * 10000 // duration为0表示无限等待
@@ -173,7 +177,7 @@ func (t *BaseTask) GetResult(duration time.Duration) (retVal []interface{}, err
case <-t.finishChan:
t.isGetResultCalled = true
timer.Stop()
return t.Result, t.Err
return t.Result, t.OriginalErr
case <-timer.C:
}
return nil, ErrTaskNotFinished
@@ -271,6 +275,18 @@ func (t *BaseTask) GetNoticeMsg() string {
return t.NoticeMsg
}
func (t *BaseTask) GetOriginalErr() error {
t.locker.RLock()
defer t.locker.RUnlock()
return t.OriginalErr
}
func (t *BaseTask) GetDetailErrList() []error {
t.locker.RLock()
defer t.locker.RUnlock()
return t.detailErrList
}
func AddChild(parentTask ITask, task ITask) ITask {
if parentTask != nil {
return parentTask.AddChild(task)
@@ -365,8 +381,12 @@ func (t *BaseTask) setStatus(status int) {
}
func (t *BaseTask) buildTaskErrFromDetail() (err error) {
if len(t.detailErrMsgList) > 0 {
return NewTaskError(t.Name, fmt.Errorf("总共:%d, 失败:%d, 详情:\n%s", t.TotalItemCount, t.FailedItemCount, strings.Join(t.detailErrMsgList, "\n")))
if len(t.detailErrList) > 0 {
strList := make([]string, len(t.detailErrList))
for k, v := range t.detailErrList {
strList[k] = v.Error()
}
return NewTaskError(t.Name, fmt.Errorf("总共:%d, 失败:%d, 详情:\n%s", t.TotalItemCount, t.FailedItemCount, strings.Join(strList, "\n")))
}
return nil
}