From 164b6a557496c3cab5785dbcb5fd832cccfc7ed5 Mon Sep 17 00:00:00 2001 From: Herb Brewer Date: Thu, 6 Aug 2020 08:55:19 +0800 Subject: [PATCH] fix: retry when connect to eventbus in sensor (#816) --- 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()