diff --git a/spider/controller.go b/spider/controller.go index b8bcfe8..c611e5f 100644 --- a/spider/controller.go +++ b/spider/controller.go @@ -126,6 +126,8 @@ func (c *Controller) providerChange(ctx context.Context, message string) error { c.provider.CalculateProcess = provider.CalculateProcess if needUpdate { + provider.Status = v2.ProviderStatus_Calculating + _ = c.storage.Provider().UpdateStatus(provider) var results = make([]v2.ProviderArticle, 0, 20) err = c.storage.ProviderArticle().FindInBatches(storage.NewGetProviderArticleQuery().SetProviderId(c.providerId), &results, func(tx *gorm.DB, batch int) error { for idx := range results { @@ -135,8 +137,19 @@ func (c *Controller) providerChange(ctx context.Context, message string) error { "exchangeRate": c.provider.Config.ExchangeRate, }) } - return tx.Select("id", "cost").Save(&results).Error + if err = tx.Select("id", "cost").Save(&results).Error; err != nil { + return err + } + ids := lo.Map(results, func(item v2.ProviderArticle, index int) string { + return fmt.Sprintf("%d", item.ID) + }) + if err = c.subscribeClient.Publish(c.ctx, utils.ProfitRate_Channel, strings.Join(ids, ",")); err != nil { + logrus.Errorf("通知商品利润率失败: %v", err) + } + return nil }) + provider.Status = v2.ProviderStatus_Normal + _ = c.storage.Provider().UpdateStatus(provider) } return err }