From a1c4e91924c5957a23aa32a2f325ea95c0a6690f Mon Sep 17 00:00:00 2001 From: ulya-sidorina Date: Thu, 3 Oct 2024 12:03:01 +0200 Subject: [PATCH] fix(OpaerationService): set DELETING sbackup tatus in DeleteBackup --- internal/handlers/delete_backup.go | 5 +---- internal/server/services/backup/backup_service.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/handlers/delete_backup.go b/internal/handlers/delete_backup.go index a4193cbb..d5d40392 100644 --- a/internal/handlers/delete_backup.go +++ b/internal/handlers/delete_backup.go @@ -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) } diff --git a/internal/server/services/backup/backup_service.go b/internal/server/services/backup/backup_service.go index 05e3573e..22fc3c3b 100644 --- a/internal/server/services/backup/backup_service.go +++ b/internal/server/services/backup/backup_service.go @@ -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, @@ -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 }