Rollback and log when commit fails

This commit is contained in:
Abin Simon
2022-03-21 12:17:22 +05:30
parent b305edc57e
commit b1e6981dcf
4 changed files with 20 additions and 10 deletions

View File

@@ -292,7 +292,8 @@ func (es *clusterService) Create(ctx context.Context, cluster *infrav3.Cluster)
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
ev := event.Resource{

View File

@@ -316,7 +316,8 @@ func (s *groupService) Create(ctx context.Context, group *userv3.Group) (*userv3
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
return group, nil
}
@@ -450,7 +451,8 @@ func (s *groupService) Update(ctx context.Context, group *userv3.Group) (*userv3
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
// update spec and status
@@ -499,7 +501,8 @@ func (s *groupService) Delete(ctx context.Context, group *userv3.Group) (*userv3
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
return group, nil
}

View File

@@ -177,7 +177,8 @@ func (s *roleService) Create(ctx context.Context, role *rolev3.Role) (*rolev3.Ro
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
return role, nil
@@ -279,7 +280,8 @@ func (s *roleService) Update(ctx context.Context, role *rolev3.Role) (*rolev3.Ro
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
return role, nil
}
@@ -320,7 +322,8 @@ func (s *roleService) Delete(ctx context.Context, role *rolev3.Role) (*rolev3.Ro
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
return role, nil
}

View File

@@ -277,7 +277,8 @@ func (s *userService) Create(ctx context.Context, user *userv3.User) (*userv3.Us
}
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
rl, err := s.ap.GetRecoveryLink(ctx, id)
@@ -430,7 +431,8 @@ func (s *userService) Update(ctx context.Context, user *userv3.User) (*userv3.Us
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
return user, nil
}
@@ -473,7 +475,8 @@ func (s *userService) Delete(ctx context.Context, user *userv3.User) (*userrpcv3
err = tx.Commit()
if err != nil {
fmt.Println("unable to commit changes", err)
tx.Rollback()
_log.Warn("unable to commit changes", err)
}
return &userrpcv3.DeleteUserResponse{}, nil
}