From 2aaec5dbd999cd80d008487d071336b1d72fef23 Mon Sep 17 00:00:00 2001 From: Luiz Pegoraro Date: Tue, 31 Jan 2023 20:26:01 -0300 Subject: [PATCH] feat(maestro): update cache with creation of yaml. Signed-off-by: Luiz Pegoraro --- maestro/service.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/maestro/service.go b/maestro/service.go index 26d130020..0949d076e 100644 --- a/maestro/service.go +++ b/maestro/service.go @@ -11,6 +11,7 @@ package maestro import ( "context" "encoding/json" + "fmt" "strings" "github.com/go-redis/redis/v8" @@ -93,6 +94,11 @@ func (svc *maestroService) Start(ctx context.Context, cancelFunction context.Can svc.logger.Warn("failed to create deploymentEntry for sink, skipping", zap.String("sink-id", sinkRes.Id)) continue } + err = svc.updateSinkCache(ctx, data) + if err != nil { + svc.logger.Warn("failed to update cache for sink", zap.String("sink-id", sinkRes.Id)) + continue + } svc.logger.Info("successfully created deploymentEntry for sink", zap.String("sink-id", sinkRes.Id), zap.String("state", sinkRes.State)) } @@ -135,6 +141,23 @@ func (svc *maestroService) Start(ctx context.Context, cancelFunction context.Can return nil } +func (svc *maestroService) updateSinkCache(ctx context.Context, data maestroconfig.SinkData) (err error) { + data.State = maestroconfig.Unknown + keyPrefix := "sinker_key" + skey := fmt.Sprintf("%s-%s:%s", keyPrefix, data.OwnerID, data.SinkID) + bytes, err := json.Marshal(data) + if err != nil { + return err + } + if err = svc.sinkerRedisClient.Set(ctx, skey, bytes, 0).Err(); err != nil { + return err + } + if err != nil { + return err + } + return +} + func (svc *maestroService) subscribeToSinkerES(ctx context.Context) { if err := svc.eventStore.SubscribeSinker(ctx); err != nil { svc.logger.Error("Bootstrap service failed to subscribe to event sourcing sinker", zap.Error(err))