Skip to content

Commit

Permalink
fix(OpaerationService): set DELETING sbackup tatus in DeleteBackup
Browse files Browse the repository at this point in the history
  • Loading branch information
ulya-sidorina committed Oct 3, 2024
1 parent 6d7d6c4 commit a1c4e91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 1 addition & 4 deletions internal/handlers/delete_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,8 @@ func DBOperationHandler(
switch dbOp.State {
case types.OperationStatePending:
{
backupToWrite.Status = types.BackupStateDeleting
operation.SetState(types.OperationStateRunning)
err := db.ExecuteUpsert(
ctx, queryBulderFactory().WithUpdateOperation(operation).WithUpdateBackup(backupToWrite),
)
err := db.UpdateOperation(ctx, operation)
if err != nil {
return fmt.Errorf("can't update operation: %v", err)
}
Expand Down
12 changes: 9 additions & 3 deletions internal/server/services/backup/backup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (s *BackupService) DeleteBackup(ctx context.Context, req *pb.DeleteBackupRe

now := timestamppb.Now()
op := &types.DeleteBackupOperation{
ID: types.GenerateObjectID(),
ContainerID: backup.ContainerID,
BackupID: req.GetBackupId(),
State: types.OperationStatePending,
Expand All @@ -166,14 +167,19 @@ func (s *BackupService) DeleteBackup(ctx context.Context, req *pb.DeleteBackupRe
UpdatedAt: now,
}

operationID, err := s.driver.CreateOperation(ctx, op)
backupToWrite := types.Backup{
ID: req.GetBackupId(),
Status: types.BackupStateDeleting,
}

err = s.driver.ExecuteUpsert(
ctx, queries.NewWriteTableQuery().WithCreateOperation(op).WithUpdateBackup(backupToWrite),
)
if err != nil {
xlog.Error(ctx, "can't create operation", zap.Error(err))
return nil, status.Error(codes.Internal, "can't create operation")
}
ctx = xlog.With(ctx, zap.String("OperationID", operationID))

op.ID = operationID
xlog.Debug(ctx, "DeleteBackup was started successfully", zap.String("operation", types.OperationToString(op)))
return op.Proto(), nil
}
Expand Down

0 comments on commit a1c4e91

Please sign in to comment.