fix: 上传日志显示 Shopee 商品 ID
This commit is contained in:
+16
-15
@@ -46,20 +46,21 @@ func (a *App) UploadVideos(productIDs []string) (uploadErr error) {
|
||||
func (a *App) uploadOneVideo(ctx context.Context, client *erpgo.Client, id string, count int) {
|
||||
p, found, err := a.db.GetProduct(id)
|
||||
if err != nil || !found {
|
||||
a.log.Error("商品 %s 无法读取上传信息", id)
|
||||
a.log.Error("货憨憨商品 %s 无法读取上传信息", id)
|
||||
return
|
||||
}
|
||||
logID := fmt.Sprintf("%s(货憨憨 ID %s)", p.ItemID, p.ID)
|
||||
fail := func(code string) {
|
||||
if err := a.db.UpdateProductStatus(p.ID, "", "", store.UploadFailed, code); err != nil {
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", p.ID, err)
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", logID, err)
|
||||
}
|
||||
a.log.Error("商品 %s 视频上传失败:%s", p.ID, code)
|
||||
a.log.Error("商品 %s 视频上传失败:%s", logID, code)
|
||||
}
|
||||
pending := func(code string) {
|
||||
if err := a.db.UpdateProductStatus(p.ID, "", "", store.UploadUnconfirmed, code); err != nil {
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", p.ID, err)
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", logID, err)
|
||||
}
|
||||
a.log.Warn("商品 %s 上传结果待确认:%s;再次操作只查询原任务", p.ID, code)
|
||||
a.log.Warn("商品 %s 上传结果待确认:%s;再次操作只查询原任务", logID, code)
|
||||
}
|
||||
previous, exists, err := a.db.GetUploadOperation(p.ID)
|
||||
if err != nil {
|
||||
@@ -81,7 +82,7 @@ func (a *App) uploadOneVideo(ctx context.Context, client *erpgo.Client, id strin
|
||||
return
|
||||
}
|
||||
if exists && previous.Status != "succeeded" && previous.Status != "failed" {
|
||||
a.waitVideoOperation(ctx, client, previous, p, pending, fail)
|
||||
a.waitVideoOperation(ctx, client, previous, p, logID, pending, fail)
|
||||
return
|
||||
}
|
||||
current, err := client.GetCurrentVideo(ctx, p.ItemID)
|
||||
@@ -93,9 +94,9 @@ func (a *App) uploadOneVideo(ctx context.Context, client *erpgo.Client, id strin
|
||||
lastError += " requestId=" + videoErr.RequestID
|
||||
}
|
||||
if updateErr := a.db.UpdateProductStatus(p.ID, "", "", store.UploadUnconfirmed, lastError); updateErr != nil {
|
||||
a.log.Error("商品 %s 保存视频状态未确认结果失败:%v", p.ID, updateErr)
|
||||
a.log.Error("商品 %s 保存视频状态未确认结果失败:%v", logID, updateErr)
|
||||
}
|
||||
a.log.Warn("商品 %s 视频状态无法确认,上传未提交:%s", p.ID, uploadRequestSummary(err))
|
||||
a.log.Warn("商品 %s 视频状态无法确认,上传未提交:%s", logID, uploadRequestSummary(err))
|
||||
return
|
||||
}
|
||||
fail(videoCode(err))
|
||||
@@ -107,7 +108,7 @@ func (a *App) uploadOneVideo(ctx context.Context, client *erpgo.Client, id strin
|
||||
}
|
||||
if current.Confirmed() && count > 1 {
|
||||
if err := a.db.UpdateProductStatus(p.ID, "", "", store.UploadSkippedExisting, ""); err != nil {
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", p.ID, err)
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", logID, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -118,7 +119,7 @@ func (a *App) uploadOneVideo(ctx context.Context, client *erpgo.Client, id strin
|
||||
}
|
||||
if !found {
|
||||
if err := a.db.UpdateProductStatus(p.ID, "", "", store.UploadMissingVideo, ""); err != nil {
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", p.ID, err)
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", logID, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -129,7 +130,7 @@ func (a *App) uploadOneVideo(ctx context.Context, client *erpgo.Client, id strin
|
||||
}
|
||||
if reason != "" {
|
||||
if err := a.db.UpdateProductStatus(p.ID, "", "", store.UploadInvalidVideo, reason); err != nil {
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", p.ID, err)
|
||||
a.log.Error("商品 %s 更新上传状态失败:%v", logID, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -174,12 +175,12 @@ func (a *App) uploadOneVideo(ctx context.Context, client *erpgo.Client, id strin
|
||||
}
|
||||
// HTTP/网络异常后的结果有歧义;查询原键,不再次 PUT。
|
||||
if putErr != nil {
|
||||
a.log.Warn("商品 %s 提交结果未确认:%s", p.ID, videoCode(putErr))
|
||||
a.log.Warn("商品 %s 提交结果未确认:%s", logID, videoCode(putErr))
|
||||
}
|
||||
a.waitVideoOperation(ctx, client, op, p, pending, fail)
|
||||
a.waitVideoOperation(ctx, client, op, p, logID, pending, fail)
|
||||
}
|
||||
|
||||
func (a *App) waitVideoOperation(ctx context.Context, client *erpgo.Client, op store.UploadOperation, p store.Product, pending, fail func(string)) {
|
||||
func (a *App) waitVideoOperation(ctx context.Context, client *erpgo.Client, op store.UploadOperation, p store.Product, logID string, pending, fail func(string)) {
|
||||
for attempt := 0; attempt < 6; attempt++ {
|
||||
if attempt > 0 {
|
||||
select {
|
||||
@@ -214,7 +215,7 @@ func (a *App) waitVideoOperation(ctx context.Context, client *erpgo.Client, op s
|
||||
pending("LOCAL_STATUS_ERROR")
|
||||
return
|
||||
}
|
||||
a.log.Success("商品 %s 的 erpgo 视频操作已确认成功", p.ID)
|
||||
a.log.Success("商品 %s 的 erpgo 视频操作已确认成功", logID)
|
||||
return
|
||||
case "failed":
|
||||
code := remote.ErrorCode
|
||||
|
||||
Reference in New Issue
Block a user