From 85e5d569d9c7ea4180dd9128a75efc9cca0597a5 Mon Sep 17 00:00:00 2001 From: ko_oler <kooler89@gmail.com> Date: Wed, 6 Dec 2023 16:38:22 +0300 Subject: [PATCH] =?UTF-8?q?-=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20Setup:=20WithWaitForSpace,=20WaitForSpace,=20Set?= =?UTF-8?q?Attempts,=20SetDelay=20-=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D0=B8=D0=B3=D0=BD=D0=B0=D1=82=D1=83=D1=80?= =?UTF-8?q?=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B9=20CheckIsSp?= =?UTF-8?q?aceAvailableWithRetry,=20CheckIsReadAvailableWithRetry=20-=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/setup/setup.go | 50 ++++++++++++-- pkg/setup/setup_test.go | 149 ++++------------------------------------ pkg/spaces/service.go | 14 ++-- 3 files changed, 63 insertions(+), 150 deletions(-) diff --git a/pkg/setup/setup.go b/pkg/setup/setup.go index b2999579..4b85d653 100644 --- a/pkg/setup/setup.go +++ b/pkg/setup/setup.go @@ -2,6 +2,7 @@ package setup import ( "context" + "time" "git.perx.ru/perxis/perxis-go/pkg/clients" "git.perx.ru/perxis/perxis-go/pkg/collections" @@ -33,6 +34,10 @@ type Setup struct { force bool remove bool + waitForSpace bool + attempts uint + delay time.Duration + errors []error logger *zap.Logger } @@ -72,6 +77,34 @@ func (s *Setup) IsRemove() bool { return s.remove } +func (s *Setup) WithWaitForSpace(wait bool) *Setup { + setup := *s + setup.waitForSpace = wait + if setup.attempts == 0 { + setup.attempts = 60000 + } + if setup.delay.Milliseconds() == 0 { + setup.delay = 100 * time.Millisecond + } + return &setup +} + +func (s *Setup) WaitForSpace() bool { + return s.waitForSpace +} + +func (s *Setup) SetAttempts(attempts uint) *Setup { + setup := *s + setup.attempts = attempts + return &setup +} + +func (s *Setup) SetDelay(delay time.Duration) *Setup { + setup := *s + setup.delay = delay + return &setup +} + func (s *Setup) HasErrors() bool { return len(s.errors) > 0 } @@ -147,7 +180,10 @@ func (s *Setup) AddItem(item *items.Item, opt ...ItemsOption) *Setup { // Install выполняет установку необходимых требований func (s *Setup) Install(ctx context.Context) error { - err := spaces.CheckIsSpaceAvailableWithRetry(ctx, s.content.Spaces, s.SpaceID, s.logger) + var err error + if s.waitForSpace { + err = spaces.CheckIsSpaceAvailableWithRetry(ctx, s.content.Spaces, s.SpaceID, s.delay, s.attempts, s.logger) + } if err == nil { if err := s.InstallRoles(ctx); err != nil { return err @@ -161,15 +197,16 @@ func (s *Setup) Install(ctx context.Context) error { if err := s.InstallItems(ctx); err != nil { return err } - s.logger.Info("Install finished", zap.String(s.SpaceID, "spaceID")) - return nil } return err } // Check выполняет проверку требований func (s *Setup) Check(ctx context.Context) error { - err := spaces.CheckIsReadAvailableWithRetry(ctx, s.content.Spaces, s.SpaceID, s.logger) + var err error + if s.waitForSpace { + err = spaces.CheckIsReadAvailableWithRetry(ctx, s.content.Spaces, s.SpaceID, s.delay, s.attempts, s.logger) + } if err == nil { if err := s.CheckRoles(ctx); err != nil { return err @@ -191,7 +228,10 @@ func (s *Setup) Check(ctx context.Context) error { // Uninstall выполняет удаление установленных раннее требований func (s *Setup) Uninstall(ctx context.Context) error { - err := spaces.CheckIsSpaceAvailableWithRetry(ctx, s.content.Spaces, s.SpaceID, s.logger) + var err error + if s.waitForSpace { + err = spaces.CheckIsSpaceAvailableWithRetry(ctx, s.content.Spaces, s.SpaceID, s.delay, s.attempts, s.logger) + } if err == nil { // В случае если необходимо удалить данные удаляем все что создано при установке расширения if err := s.UninstallClients(ctx); err != nil { diff --git a/pkg/setup/setup_test.go b/pkg/setup/setup_test.go index 82d4849e..10313d0b 100644 --- a/pkg/setup/setup_test.go +++ b/pkg/setup/setup_test.go @@ -97,15 +97,11 @@ func TestSetupInstall(t *testing.T) { t.Run("Success, nothing to install", func(t *testing.T) { logger := zaptest.NewLogger(t, zaptest.WrapOptions()) - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger) - + setup := NewSetup(nil, spaceID, envID, logger) err := setup.Install(context.Background()) require.NoError(t, err) - sp.AssertExpectations(t) }) t.Run("Success, no force", func(t *testing.T) { @@ -165,16 +161,12 @@ func TestSetupInstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Items: itmMock, Environments: envMocks, - Spaces: sp, }, t) err := setup.Install(context.Background()) @@ -187,7 +179,6 @@ func TestSetupInstall(t *testing.T) { clMock.AssertExpectations(t) itmMock.AssertExpectations(t) envMocks.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Success, update existing records", func(t *testing.T) { @@ -231,16 +222,12 @@ func TestSetupInstall(t *testing.T) { Return(nil). Times(len(itms)) - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Items: itmMock, Environments: envMocks, - Spaces: sp, }, t) err := setup.Install(context.Background()) @@ -253,7 +240,6 @@ func TestSetupInstall(t *testing.T) { clMock.AssertExpectations(t) itmMock.AssertExpectations(t) envMocks.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Success, with force", func(t *testing.T) { @@ -290,15 +276,11 @@ func TestSetupInstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Items: itmMock, - Spaces: sp, }, t) setup = setup.WithForce(true) @@ -319,12 +301,8 @@ func TestSetupInstall(t *testing.T) { Return(nil, errors.New("can't get role")). Once() - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ - Roles: rMock, - Spaces: sp, + Roles: rMock, }, t) err := setup.Install(context.Background()) @@ -333,7 +311,6 @@ func TestSetupInstall(t *testing.T) { assert.ErrorContains(t, err, "failed to install role") rMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't install client, storage returns error", func(t *testing.T) { @@ -355,13 +332,9 @@ func TestSetupInstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Clients: clMock, Roles: rMock, - Spaces: sp, }, t) err := setup.Install(context.Background()) @@ -371,7 +344,6 @@ func TestSetupInstall(t *testing.T) { rMock.AssertExpectations(t) clMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't get collection, storage returns error", func(t *testing.T) { @@ -404,14 +376,10 @@ func TestSetupInstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, - Spaces: sp, }, t) err := setup.Install(context.Background()) @@ -422,7 +390,6 @@ func TestSetupInstall(t *testing.T) { rMock.AssertExpectations(t) collsMock.AssertExpectations(t) clMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't create collection, storage returns error", func(t *testing.T) { @@ -459,14 +426,10 @@ func TestSetupInstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, - Spaces: sp, }, t) err := setup.Install(context.Background()) @@ -477,7 +440,6 @@ func TestSetupInstall(t *testing.T) { rMock.AssertExpectations(t) collsMock.AssertExpectations(t) clMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't update collection, storage returns error", func(t *testing.T) { @@ -507,14 +469,10 @@ func TestSetupInstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, - Spaces: sp, }, t) err := setup.Install(context.Background()) @@ -525,7 +483,6 @@ func TestSetupInstall(t *testing.T) { rMock.AssertExpectations(t) collsMock.AssertExpectations(t) clMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't set schema, storage returns error", func(t *testing.T) { @@ -566,14 +523,10 @@ func TestSetupInstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, - Spaces: sp, }, t) err := setup.Install(context.Background()) @@ -584,7 +537,6 @@ func TestSetupInstall(t *testing.T) { rMock.AssertExpectations(t) collsMock.AssertExpectations(t) clMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't migrate, storage returns error", func(t *testing.T) { @@ -630,15 +582,11 @@ func TestSetupInstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Environments: envMocks, - Spaces: sp, }, t) err := setup.Install(context.Background()) @@ -649,7 +597,6 @@ func TestSetupInstall(t *testing.T) { rMock.AssertExpectations(t) collsMock.AssertExpectations(t) clMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't find action, storage returns error", func(t *testing.T) { @@ -697,16 +644,12 @@ func TestSetupInstall(t *testing.T) { Return(nil, errors.New("can't create item")). Once() - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Items: itmMock, Environments: envMocks, - Spaces: sp, }, t) setup = setup.WithForce(true) @@ -729,7 +672,7 @@ func TestSetupInstall(t *testing.T) { sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger) - err := setup.Install(context.Background()) + err := setup.WithWaitForSpace(true).Install(context.Background()) require.NoError(t, err) @@ -742,8 +685,7 @@ func TestSetupInstall(t *testing.T) { sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", State: spaces.StateMigration}, nil).Twice() sp.On("Get", mock.Anything, mock.Anything).Return(nil, errors.New("some error")).Once() setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger) - - err := setup.Install(context.Background()) + err := setup.WithWaitForSpace(true).Install(context.Background()) require.Error(t, err, "в момент выполнения пришла ошибка отличная от 'space not available'") @@ -838,16 +780,12 @@ func TestSetupUninstall(t *testing.T) { t.Run("Success, nothing to uninstall", func(t *testing.T) { logger := zaptest.NewLogger(t, zaptest.WrapOptions()) - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - - setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger) + setup := NewSetup(nil, spaceID, envID, logger) err := setup.Uninstall(context.Background()) require.NoError(t, err) - sp.AssertExpectations(t) }) t.Run("Remove", func(t *testing.T) { @@ -883,15 +821,11 @@ func TestSetupUninstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Items: itmMock, - Spaces: sp, }, t) setup = setup.WithRemove(true) @@ -904,7 +838,6 @@ func TestSetupUninstall(t *testing.T) { collsMock.AssertExpectations(t) clMock.AssertExpectations(t) itmMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Remove, with clients NotFound error", func(t *testing.T) { @@ -940,15 +873,11 @@ func TestSetupUninstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Items: itmMock, - Spaces: sp, }, t) setup = setup.WithRemove(true) @@ -961,7 +890,6 @@ func TestSetupUninstall(t *testing.T) { collsMock.AssertExpectations(t) clMock.AssertExpectations(t) itmMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't uninstall clients, storage returns error", func(t *testing.T) { @@ -979,14 +907,10 @@ func TestSetupUninstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Clients: clMock, Roles: rMock, Items: itmMock, - Spaces: sp, }, t) setup = setup.WithRemove(true) @@ -997,7 +921,7 @@ func TestSetupUninstall(t *testing.T) { rMock.AssertExpectations(t) clMock.AssertExpectations(t) - sp.AssertExpectations(t) + }) t.Run("Can't uninstall role, storage returns error", func(t *testing.T) { @@ -1018,14 +942,10 @@ func TestSetupUninstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Roles: rMock, Clients: clMock, Items: itmMock, - Spaces: sp, }, t) setup = setup.WithRemove(true) @@ -1035,7 +955,6 @@ func TestSetupUninstall(t *testing.T) { assert.ErrorContains(t, err, "failed to uninstall role") rMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't uninstall collections, storage returns error", func(t *testing.T) { @@ -1063,15 +982,11 @@ func TestSetupUninstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Items: itmMock, - Spaces: sp, }, t) setup = setup.WithRemove(true) @@ -1083,7 +998,6 @@ func TestSetupUninstall(t *testing.T) { rMock.AssertExpectations(t) collsMock.AssertExpectations(t) clMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't uninstall actions, storage returns error", func(t *testing.T) { @@ -1117,15 +1031,11 @@ func TestSetupUninstall(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Items: itmMock, - Spaces: sp, }, t) setup = setup.WithRemove(true) @@ -1135,7 +1045,6 @@ func TestSetupUninstall(t *testing.T) { assert.ErrorContains(t, err, "failed to uninstall item") itmMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Success on retry when space not available", func(t *testing.T) { @@ -1147,7 +1056,7 @@ func TestSetupUninstall(t *testing.T) { setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger) - err := setup.Uninstall(context.Background()) + err := setup.WithWaitForSpace(true).Uninstall(context.Background()) require.NoError(t, err) @@ -1163,11 +1072,9 @@ func TestSetupUninstall(t *testing.T) { setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger) - err := setup.Uninstall(context.Background()) + err := setup.WithWaitForSpace(true).Uninstall(context.Background()) require.Error(t, err, "в момент выполнения пришла ошибка отличная от 'space not available'") - - sp.AssertExpectations(t) }) } @@ -1181,16 +1088,11 @@ func TestSetupCheck(t *testing.T) { t.Run("Success, nothing to check", func(t *testing.T) { logger := zaptest.NewLogger(t, zaptest.WrapOptions()) - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - - setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger) + setup := NewSetup(nil, spaceID, envID, logger) err := setup.Check(context.Background()) require.NoError(t, err) - - sp.AssertExpectations(t) }) t.Run("Success", func(t *testing.T) { @@ -1226,15 +1128,11 @@ func TestSetupCheck(t *testing.T) { mock.MatchedBy(func(opt *items.FindOptions) bool { return opt.Regular && opt.Hidden && opt.Templates }), ).Return(getActions(), 0, nil).Once() - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Collections: collsMock, Clients: clMock, Roles: rMock, Items: itmMock, - Spaces: sp, }, t) err := setup.Check(context.Background()) @@ -1246,7 +1144,6 @@ func TestSetupCheck(t *testing.T) { collsMock.AssertExpectations(t) clMock.AssertExpectations(t) itmMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't get role, storage returns error", func(t *testing.T) { @@ -1255,12 +1152,8 @@ func TestSetupCheck(t *testing.T) { Return(nil, errors.New("can't get role")). Once() - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ - Roles: rMock, - Spaces: sp, + Roles: rMock, }, t) err := setup.Check(context.Background()) @@ -1269,7 +1162,6 @@ func TestSetupCheck(t *testing.T) { assert.ErrorContains(t, err, "role check error") rMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't get client, storage returns error", func(t *testing.T) { @@ -1285,13 +1177,9 @@ func TestSetupCheck(t *testing.T) { Return(nil, errors.New("can't get client")). Once() - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Roles: rMock, Clients: clMock, - Spaces: sp, }, t) err := setup.Check(context.Background()) @@ -1301,7 +1189,6 @@ func TestSetupCheck(t *testing.T) { rMock.AssertExpectations(t) clMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't get collection, storage returns error", func(t *testing.T) { @@ -1324,14 +1211,10 @@ func TestSetupCheck(t *testing.T) { Once() } - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Roles: rMock, Clients: clMock, Collections: collsMock, - Spaces: sp, }, t) err := setup.Check(context.Background()) @@ -1342,7 +1225,6 @@ func TestSetupCheck(t *testing.T) { rMock.AssertExpectations(t) clMock.AssertExpectations(t) collsMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Can't get action, storage returns error", func(t *testing.T) { @@ -1372,15 +1254,11 @@ func TestSetupCheck(t *testing.T) { Return(nil, 0, nil). Once() - sp := &mocks.Spaces{} - sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once() - setup := newSetup(&content.Content{ Roles: rMock, Clients: clMock, Collections: collsMock, Items: itmMock, - Spaces: sp, }, t) err := setup.Check(context.Background()) @@ -1391,7 +1269,6 @@ func TestSetupCheck(t *testing.T) { rMock.AssertExpectations(t) clMock.AssertExpectations(t) collsMock.AssertExpectations(t) - sp.AssertExpectations(t) }) t.Run("Success on retry when space is preparing", func(t *testing.T) { @@ -1403,7 +1280,7 @@ func TestSetupCheck(t *testing.T) { setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger) - err := setup.Check(context.Background()) + err := setup.WithWaitForSpace(true).Check(context.Background()) require.NoError(t, err) @@ -1419,11 +1296,9 @@ func TestSetupCheck(t *testing.T) { setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger) - err := setup.Check(context.Background()) + err := setup.WithWaitForSpace(true).Check(context.Background()) require.Error(t, err, "в момент выполнения пришла ошибка отличная от 'Space is migrating'") - - sp.AssertExpectations(t) }) //t.Run("Can't get task config, storage returns error", func(t *testing.T) { diff --git a/pkg/spaces/service.go b/pkg/spaces/service.go index 6f3e0eab..2483633f 100644 --- a/pkg/spaces/service.go +++ b/pkg/spaces/service.go @@ -76,7 +76,7 @@ func IsReadAvailable(ctx context.Context, svc Spaces, spaceID string) error { return errors.Errorf("space '%s' is migrating, fail to do operation", sp.ID) } -func CheckIsSpaceAvailableWithRetry(ctx context.Context, svc Spaces, spaceID string, logger *zap.Logger) error { +func CheckIsSpaceAvailableWithRetry(ctx context.Context, svc Spaces, spaceID string, delay time.Duration, attempts uint, logger *zap.Logger) error { return retry.Do( func() error { return IsSpaceAvailable(ctx, svc, spaceID) @@ -85,14 +85,13 @@ func CheckIsSpaceAvailableWithRetry(ctx context.Context, svc Spaces, spaceID str retry.OnRetry(func(n uint, err error) { logger.Warn("Space not available", zap.String("spaceID", spaceID), zap.Uint("Retry", n), zap.Error(err)) }), - retry.DelayType(retry.BackOffDelay), - retry.MaxDelay(1*time.Minute), - retry.Attempts(20), + retry.Delay(delay), + retry.Attempts(attempts), retry.Context(ctx), ) } -func CheckIsReadAvailableWithRetry(ctx context.Context, svc Spaces, spaceID string, logger *zap.Logger) error { +func CheckIsReadAvailableWithRetry(ctx context.Context, svc Spaces, spaceID string, delay time.Duration, attempts uint, logger *zap.Logger) error { return retry.Do( func() error { return IsReadAvailable(ctx, svc, spaceID) @@ -101,9 +100,8 @@ func CheckIsReadAvailableWithRetry(ctx context.Context, svc Spaces, spaceID stri retry.OnRetry(func(n uint, err error) { logger.Warn("Space is migrating", zap.String("spaceID", spaceID), zap.Uint("Retry", n), zap.Error(err)) }), - retry.DelayType(retry.BackOffDelay), - retry.MaxDelay(1*time.Minute), - retry.Attempts(20), + retry.Delay(delay), + retry.Attempts(attempts), retry.Context(ctx), ) } -- GitLab