fix(accounts): unschedule errored accounts
This commit is contained in:
parent
49b415e333
commit
202aab8e63
@ -317,6 +317,10 @@ func (r *accountRepository) Update(ctx context.Context, account *service.Account
|
|||||||
if account == nil {
|
if account == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
schedulable := account.Schedulable
|
||||||
|
if account.Status == service.StatusError {
|
||||||
|
schedulable = false
|
||||||
|
}
|
||||||
|
|
||||||
builder := r.client.Account.UpdateOneID(account.ID).
|
builder := r.client.Account.UpdateOneID(account.ID).
|
||||||
SetName(account.Name).
|
SetName(account.Name).
|
||||||
@ -329,7 +333,7 @@ func (r *accountRepository) Update(ctx context.Context, account *service.Account
|
|||||||
SetPriority(account.Priority).
|
SetPriority(account.Priority).
|
||||||
SetStatus(account.Status).
|
SetStatus(account.Status).
|
||||||
SetErrorMessage(account.ErrorMessage).
|
SetErrorMessage(account.ErrorMessage).
|
||||||
SetSchedulable(account.Schedulable).
|
SetSchedulable(schedulable).
|
||||||
SetAutoPauseOnExpired(account.AutoPauseOnExpired)
|
SetAutoPauseOnExpired(account.AutoPauseOnExpired)
|
||||||
|
|
||||||
if account.RateMultiplier != nil {
|
if account.RateMultiplier != nil {
|
||||||
@ -716,6 +720,7 @@ func (r *accountRepository) SetError(ctx context.Context, id int64, errorMsg str
|
|||||||
Where(dbaccount.IDEQ(id)).
|
Where(dbaccount.IDEQ(id)).
|
||||||
SetStatus(service.StatusError).
|
SetStatus(service.StatusError).
|
||||||
SetErrorMessage(errorMsg).
|
SetErrorMessage(errorMsg).
|
||||||
|
SetSchedulable(false).
|
||||||
Save(ctx)
|
Save(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -729,7 +729,7 @@ func (s *AccountRepoSuite) TestUpdateLastUsed() {
|
|||||||
// --- SetError ---
|
// --- SetError ---
|
||||||
|
|
||||||
func (s *AccountRepoSuite) TestSetError() {
|
func (s *AccountRepoSuite) TestSetError() {
|
||||||
account := mustCreateAccount(s.T(), s.client, &service.Account{Name: "acc-err", Status: service.StatusActive})
|
account := mustCreateAccount(s.T(), s.client, &service.Account{Name: "acc-err", Status: service.StatusActive, Schedulable: true})
|
||||||
|
|
||||||
s.Require().NoError(s.repo.SetError(s.ctx, account.ID, "something went wrong"))
|
s.Require().NoError(s.repo.SetError(s.ctx, account.ID, "something went wrong"))
|
||||||
|
|
||||||
@ -737,6 +737,22 @@ func (s *AccountRepoSuite) TestSetError() {
|
|||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(service.StatusError, got.Status)
|
s.Require().Equal(service.StatusError, got.Status)
|
||||||
s.Require().Equal("something went wrong", got.ErrorMessage)
|
s.Require().Equal("something went wrong", got.ErrorMessage)
|
||||||
|
s.Require().False(got.Schedulable)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AccountRepoSuite) TestUpdateErrorStatusUnschedulesAccount() {
|
||||||
|
account := mustCreateAccount(s.T(), s.client, &service.Account{Name: "acc-update-err", Status: service.StatusActive, Schedulable: true})
|
||||||
|
account.Status = service.StatusError
|
||||||
|
account.ErrorMessage = "token revoked"
|
||||||
|
account.Schedulable = true
|
||||||
|
|
||||||
|
s.Require().NoError(s.repo.Update(s.ctx, account))
|
||||||
|
|
||||||
|
got, err := s.repo.GetByID(s.ctx, account.ID)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(service.StatusError, got.Status)
|
||||||
|
s.Require().Equal("token revoked", got.ErrorMessage)
|
||||||
|
s.Require().False(got.Schedulable)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AccountRepoSuite) TestClearError_SyncSchedulerSnapshotOnRecovery() {
|
func (s *AccountRepoSuite) TestClearError_SyncSchedulerSnapshotOnRecovery() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user