Skip to content

Commit

Permalink
get listeners from cache
Browse files Browse the repository at this point in the history
Signed-off-by: nnnkkk7 <[email protected]>
  • Loading branch information
nnnkkk7 committed Sep 16, 2023
1 parent 5089af1 commit 730d6e9
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions pkg/app/piped/executor/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"go.uber.org/zap"
Expand Down Expand Up @@ -416,18 +417,23 @@ func routing(ctx context.Context, in *executor.Input, platformProviderName strin
in.Logger.Error("Failed to store traffic routing config to metadata store", zap.Error(err))
}

currListenerArns, err := client.GetListenerArns(ctx, primaryTargetGroup)
if err != nil {
in.LogPersister.Errorf("Failed to get current active listeners: %v", err)
return false
var currListenerArns []string
value, ok := in.MetadataStore.Shared().Get(currentListenersKey)
if ok {
currListenerArns = strings.Split(value, ",")
} else {
currListenerArns, err = client.GetListenerArns(ctx, primaryTargetGroup)
if err != nil {
in.LogPersister.Errorf("Failed to get current active listeners: %v", err)
return false
}
}

// Store created listeners to use later.
metadataListeners := make(map[string]string, len(currListenerArns))
for i, v := range currListenerArns {
metadataListeners[fmt.Sprintf(currentListenersKey+"-%d", i)] = v
}
if err := in.MetadataStore.Shared().PutMulti(ctx, metadataListeners); err != nil {
addedListeners := make([]string, 0, len(currListenerArns))
addedListeners = append(addedListeners, currListenerArns...)
metadata := strings.Join(addedListeners, ",")
if err := in.MetadataStore.Shared().Put(ctx, currentListenersKey, metadata); err != nil {
in.LogPersister.Errorf("Unable to store created listeners to metadata store: %v", err)
return false
}
Expand Down

0 comments on commit 730d6e9

Please sign in to comment.