From 97d4d01ff076b8d16aa5a583e66234f902b802d6 Mon Sep 17 00:00:00 2001 From: dmtgrinevich Date: Wed, 4 Oct 2023 18:08:49 +0000 Subject: [PATCH] allocation resources panic fix --- cachemaps/resourcesToAllocate/resourcesToAllocate.go | 6 +++++- service/taskRegistrar.go | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cachemaps/resourcesToAllocate/resourcesToAllocate.go b/cachemaps/resourcesToAllocate/resourcesToAllocate.go index 279c233b..045fceb9 100644 --- a/cachemaps/resourcesToAllocate/resourcesToAllocate.go +++ b/cachemaps/resourcesToAllocate/resourcesToAllocate.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" + "github.com/go-redis/redis/v8" "github.com/zebrunner/esg/config" ) @@ -37,10 +38,13 @@ func GetAllEntities() ([]*Resources, error) { return nil, err } - resources := make([]*Resources, len(keys)) + resources := make([]*Resources, 0, len(keys)) for _, uuid := range keys { data, err := config.ResourcesConnection.Get(context.Background(), uuid).Result() if err != nil { + if err == redis.Nil { + continue + } return nil, err } diff --git a/service/taskRegistrar.go b/service/taskRegistrar.go index 17c52be7..1a833d6f 100644 --- a/service/taskRegistrar.go +++ b/service/taskRegistrar.go @@ -71,10 +71,10 @@ func registerTask(ctx context.Context, env environment.ExecutionEnvironment, wai var resultRunTask *ecs.RunTaskOutput resultRunTask, err := svc.RunTask(runTaskInput) if err != nil { - l.WithError(err).Error("Task register failed.") // Not good solution but aws doesn't give a choice errStr := err.Error() if errStr == "ClientException: TaskDefinition not found." { + l.WithError(err).Error("Task register failed.") if markedToAllocate { resourcesToAllocate.RemoveEntity(env.RouterUUID) } @@ -83,6 +83,7 @@ func registerTask(ctx context.Context, env environment.ExecutionEnvironment, wai } if errStr == "ClientException: Tasks provisioning capacity limit exceeded." || strings.Contains(errStr, "ThrottlingException: Rate exceeded") { + l.WithError(err).Trace("Task register failed.") if !markedToAllocate { resources := env.CalculateResources() err := resourcesToAllocate.AddEntity(resources)