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

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

@@ -374,10 +374,3 @@ func GuessVendorIDFromVendorStoreID(vendorStoreID int64) (vendorID int) {
func GetVendorName(vendorID int) (vendorName string) {
return model.VendorChineseNames[vendorID]
}
func AddVendorInfo2Err(inErr error, vendorID int) (outErr error) {
if inErr != nil {
outErr = fmt.Errorf("处理平台%s, %s", model.VendorChineseNames[vendorID], inErr.Error())
}
return outErr
}

View File

@@ -134,13 +134,13 @@ func (task *ParallelTask) Run() {
}
} else {
globals.SugarLogger.Infof("ParallelTask.Run %s, subtask(job:%s, params:%s) result:%v, failed with error:%v", task.Name, utils.Format4Output(job, true), utils.Format4Output(task.params, true), result, err)
task.locker.Lock()
task.detailErrList = append(task.detailErrList, err)
task.locker.Unlock()
if !task.IsContinueWhenError { // 出错
chanRetVal = err
goto end
}
task.locker.Lock()
task.detailErrMsgList = append(task.detailErrMsgList, err.Error())
task.locker.Unlock()
}
}
}
@@ -188,8 +188,12 @@ func (task *ParallelTask) Run() {
}
}
if taskErr != nil {
task.OriginalErr = taskErr
task.Err = NewTaskError(task.Name, taskErr)
} else {
if len(task.detailErrList) > 0 {
task.OriginalErr = task.detailErrList[0]
}
task.Err = task.buildTaskErrFromDetail()
}
task.Result = taskResult

View File

@@ -44,13 +44,13 @@ func (task *SeqTask) Run() {
})
task.finishedOneJob(1, err)
if taskErr = err; taskErr != nil {
task.locker.Lock()
task.detailErrList = append(task.detailErrList, err)
task.locker.Unlock()
globals.SugarLogger.Infof("SeqTask.Run %s step:%d failed with error:%v", task.Name, i, err)
if !task.IsContinueWhenError {
break
}
task.locker.Lock()
task.detailErrMsgList = append(task.detailErrMsgList, err.Error())
task.locker.Unlock()
} else if result != nil {
taskResult = append(taskResult, utils.Interface2Slice(result)...)
}
@@ -68,8 +68,12 @@ func (task *SeqTask) Run() {
}
}
if taskErr != nil {
task.OriginalErr = taskErr
task.Err = NewTaskError(task.Name, taskErr)
} else {
if len(task.detailErrList) > 0 {
task.OriginalErr = task.detailErrList[0]
}
task.Err = task.buildTaskErrFromDetail()
}
task.Result = taskResult

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
}