From 1afeea44235d3e4b1e56522a674339011c85799f Mon Sep 17 00:00:00 2001 From: timerzz Date: Mon, 2 Dec 2024 19:25:39 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=94=AF=E6=8C=81=E8=B9=B2=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E5=92=8C=E5=8E=86=E5=8F=B2=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ats-tracer/controller.go | 22 +++++++++++----------- cmd/main.go | 4 +++- watcher/controller.go | 24 +++++++++++++----------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/ats-tracer/controller.go b/ats-tracer/controller.go index 14dd828..55e5a0a 100644 --- a/ats-tracer/controller.go +++ b/ats-tracer/controller.go @@ -117,17 +117,17 @@ func (c *Controller) traceRange() { }() if c.doTrace(tracer) { - // 如果蹲到了,需要通知 - //resp, err := pusher.Push(c.ctx, &push.PushReq{ - // Title: "coach 断货", - // Content: fmt.Sprintf("coach 商品 %s 断货了\n库存为0\n链接:%s", tracer.pArticle.SkuID, tracer.pArticle.Link), - //}) - //if err != nil { - // glog.Errorf("消息推送失败:%v", err) - //} - //if resp.Code != 0 { - // glog.Errorf("消息推送失败:%s", resp.Msg) - //} + //如果蹲到了,需要通知 + resp, err := pusher.Push(c.ctx, &push.PushReq{ + Title: "coach 断货", + Content: fmt.Sprintf("coach 商品 %s 断货了\n库存为0\n链接:%s", tracer.pArticle.SkuID, tracer.pArticle.Link), + }) + if err != nil { + glog.Errorf("消息推送失败:%v", err) + } + if resp.Code != 0 { + glog.Errorf("消息推送失败:%s", resp.Msg) + } tracer.pArticle.SetTraceAts(false) _ = c.storage.ProviderArticle().Update(*tracer.pArticle, "trace_ats") c.tracers.Remove(tracer.pArticle.SkuID) diff --git a/cmd/main.go b/cmd/main.go index 537ee17..2d50f41 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -16,6 +16,8 @@ import ( "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" "gitea.timerzz.com/kedaya_haitao/common/pkg/redis" "gitea.timerzz.com/kedaya_haitao/common/pkg/web" + "gitea.timerzz.com/kedaya_haitao/pusher/rpc/pusher" + "github.com/cloudwego/kitex/client" "github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3/middleware/cors" "github.com/gofiber/fiber/v3/middleware/recover" @@ -45,7 +47,7 @@ func main() { glog.Fatalf("初始化redis失败:%v", err) } - //pusher.InitClient("pusher", client.WithHostPorts("pusher:8080")) + pusher.InitClient("pusher", client.WithHostPorts("pusher:8080")) // 代理池 pool := proxy.NewProxyPool(cfg.Proxy.Subscribes) diff --git a/watcher/controller.go b/watcher/controller.go index e55cb99..0428e2f 100644 --- a/watcher/controller.go +++ b/watcher/controller.go @@ -10,6 +10,8 @@ import ( coach_client "gitea.timerzz.com/kedaya_haitao/common/pkg/coach-client" "gitea.timerzz.com/kedaya_haitao/common/structs/storage" v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2" + "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" + "gitea.timerzz.com/kedaya_haitao/pusher/rpc/pusher" "github.com/golang/glog" "gorm.io/gorm" ) @@ -114,17 +116,17 @@ func (c *Controller) watchRange() { }() if c.doWatch(watcher) { - //// 如果蹲到了,需要通知 - //resp, err := pusher.Push(c.ctx, &push.PushReq{ - // Title: "coach 补货", - // Content: fmt.Sprintf("coach 商品 %s 补货\n库存:%d\n链接:%s", watcher.pArticle.SkuID, watcher.pArticle.Ats, watcher.pArticle.Link), - //}) - //if err != nil { - // glog.Errorf("消息推送失败:%v", err) - //} - //if resp.Code != 0 { - // glog.Errorf("消息推送失败:%s", resp.Msg) - //} + // 如果蹲到了,需要通知 + resp, err := pusher.Push(c.ctx, &push.PushReq{ + Title: "coach 补货", + Content: fmt.Sprintf("coach 商品 %s 补货\n库存:%d\n链接:%s", watcher.pArticle.SkuID, watcher.pArticle.Ats, watcher.pArticle.Link), + }) + if err != nil { + glog.Errorf("消息推送失败:%v", err) + } + if resp.Code != 0 { + glog.Errorf("消息推送失败:%s", resp.Msg) + } watcher.pArticle.SetWatch(false) _ = c.storage.ProviderArticle().Update(*watcher.pArticle, "watch") c.watchers.Remove(watcher.pArticle.SkuID)