From 4c4706b1e3e2e14c2a8299a5b6d7ba2ec62caa0f Mon Sep 17 00:00:00 2001 From: Herb Date: Wed, 5 Aug 2020 16:46:56 +0800 Subject: [PATCH] fix: retry when connect to eventbus in sensor --- sensors/listener.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sensors/listener.go b/sensors/listener.go index 3ca71a6bd6..fcd329effe 100644 --- a/sensors/listener.go +++ b/sensors/listener.go @@ -33,6 +33,7 @@ import ( "github.com/argoproj/argo-events/common/logging" "github.com/argoproj/argo-events/eventbus" eventbusdriver "github.com/argoproj/argo-events/eventbus/driver" + "github.com/argoproj/argo-events/eventsources/sources" "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" sensordependencies "github.com/argoproj/argo-events/sensors/dependencies" sensortriggers "github.com/argoproj/argo-events/sensors/triggers" @@ -102,9 +103,14 @@ func (sensorCtx *SensorContext) ListenEvents(ctx context.Context, stopCh <-chan for _, t := range triggers { triggerNames = append(triggerNames, t.Template.Name) } - conn, err := ebDriver.Connect() + var conn eventbusdriver.Connection + err = sources.Connect(&common.DefaultRetry, func() error { + var err error + conn, err = ebDriver.Connect() + return err + }) if err != nil { - logger.Error("failed to connect to event bus", zap.Error(err)) + logger.Fatal("failed to connect to event bus", zap.Error(err)) return } defer conn.Close()