From 272cc7ba4cd5e43d2cb770772f8e062a7e4cca1b Mon Sep 17 00:00:00 2001 From: zema1 Date: Tue, 19 Nov 2024 11:59:59 +0800 Subject: [PATCH] fix: no push --- ctrl/config.go | 2 ++ ctrl/ctrl.go | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ctrl/config.go b/ctrl/config.go index 6a59296..dda91fc 100644 --- a/ctrl/config.go +++ b/ctrl/config.go @@ -183,6 +183,8 @@ use webhook: %s --webhook WEBHOOK_URL` if pusherCount > 1 { golog.Infof("multi pusher detected, push retry will be disabled") c.PushRetryCount = 0 + } else { + c.PushRetryCount = 2 } // 固定一个推送的间隔 1s,避免 dingding 等推送过快的问题 interval := time.Second diff --git a/ctrl/ctrl.go b/ctrl/ctrl.go index 7df545a..83241fd 100644 --- a/ctrl/ctrl.go +++ b/ctrl/ctrl.go @@ -280,17 +280,23 @@ func (w *WatchVulnApp) collectAndPush(ctx context.Context) { w.log.Infof("Pushing %s", v) // 默认重试3次,如果有多种推送方式,禁用重置机制,避免出现一个成功一个失败,重试的话,成功那个会被重复推送 - for i := 0; i < w.config.PushRetryCount; i++ { + i := 0 + for { if err := w.pushVuln(v); err == nil { // 如果两种推送都成功,才标记为已推送 _, err = dbVuln.Update().SetPushed(true).Save(ctx) if err != nil { w.log.Errorf("failed to save pushed %s status, %s", v.UniqueKey, err) } + w.log.Infof("pushed %s successfully", v) break } else { w.log.Errorf("failed to push %s, %s", v.UniqueKey, err) } + i++ + if i > w.config.PushRetryCount { + break + } w.log.Infof("retry to push %s after 30s", v.UniqueKey) time.Sleep(time.Second * 30) }