Skip to content

Commit

Permalink
fix updating backup message (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
bma13 authored Sep 12, 2024
1 parent 3ed2ee8 commit 8cac8de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions internal/connectors/db/yql/queries/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func BuildUpdateBackupQuery(backup types.Backup, index int) WriteSingleTableQuer
}
d.AddUpdateId(table_types.StringValueFromString(backup.ID))
d.AddValueParam("$status", table_types.StringValueFromString(backup.Status))
d.AddValueParam("$message", table_types.StringValueFromString(backup.Message))
if backup.Size != 0 {
d.AddValueParam("$size", table_types.Int64Value(backup.Size))

Expand Down
16 changes: 10 additions & 6 deletions internal/connectors/db/yql/queries/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

func TestQueryBuilder_UpdateUpdate(t *testing.T) {
const (
queryString = `UPDATE Backups SET status = $status_0 WHERE id = $id_0;
queryString = `UPDATE Backups SET status = $status_0, message = $message_0 WHERE id = $id_0;
UPDATE Operations SET status = $status_1, message = $message_1 WHERE id = $id_1`
)
opId := types.GenerateObjectID()
Expand All @@ -30,8 +30,9 @@ UPDATE Operations SET status = $status_1, message = $message_1 WHERE id = $id_1`
Message: "Abcde",
}
backup := types.Backup{
ID: backupId,
Status: "Available",
ID: backupId,
Status: "Available",
Message: "Message",
}
builder := NewWriteTableQuery(context.Background()).
WithUpdateBackup(backup).
Expand All @@ -40,6 +41,7 @@ UPDATE Operations SET status = $status_1, message = $message_1 WHERE id = $id_1`
queryParams = table.NewQueryParameters(
table.ValueParam("$id_0", table_types.StringValueFromString(backupId)),
table.ValueParam("$status_0", table_types.StringValueFromString("Available")),
table.ValueParam("$message_0", table_types.StringValueFromString("Message")),
table.ValueParam("$id_1", table_types.StringValueFromString(opId)),
table.ValueParam("$status_1", table_types.StringValueFromString("Done")),
table.ValueParam("$message_1", table_types.StringValueFromString("Abcde")),
Expand Down Expand Up @@ -163,7 +165,7 @@ UPSERT INTO Operations (id, type, status, message, initiated, created_at, contai

func TestQueryBuilder_UpdateCreate(t *testing.T) {
const (
queryString = `UPDATE Backups SET status = $status_0 WHERE id = $id_0;
queryString = `UPDATE Backups SET status = $status_0, message = $message_0 WHERE id = $id_0;
UPSERT INTO Operations (id, type, status, message, initiated, created_at, container_id, database, endpoint, backup_id, operation_id, paths, paths_to_exclude) VALUES ($id_1, $type_1, $status_1, $message_1, $initiated_1, $created_at_1, $container_id_1, $database_1, $endpoint_1, $backup_id_1, $operation_id_1, $paths_1, $paths_to_exclude_1)`
)
ctx := context.Background()
Expand All @@ -187,8 +189,9 @@ UPSERT INTO Operations (id, type, status, message, initiated, created_at, contai
},
}
backup := types.Backup{
ID: backupId,
Status: "Available",
ID: backupId,
Status: "Available",
Message: "Success",
}
builder := NewWriteTableQuery(ctx).
WithUpdateBackup(backup).
Expand All @@ -197,6 +200,7 @@ UPSERT INTO Operations (id, type, status, message, initiated, created_at, contai
queryParams = table.NewQueryParameters(
table.ValueParam("$id_0", table_types.StringValueFromString(backupId)),
table.ValueParam("$status_0", table_types.StringValueFromString("Available")),
table.ValueParam("$message_0", table_types.StringValueFromString("Success")),
table.ValueParam("$id_1", table_types.StringValueFromString(opId)),
table.ValueParam("$type_1", table_types.StringValueFromString("TB")),
table.ValueParam(
Expand Down
5 changes: 5 additions & 0 deletions internal/handlers/take_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TBOperationHandler(
operation.SetMessage(ydbOpResponse.opMessage)
operation.GetAudit().CompletedAt = now
backupToWrite.Status = types.BackupStateError
backupToWrite.Message = operation.GetMessage()
backupToWrite.AuditInfo.CompletedAt = now
return db.ExecuteUpsert(
ctx, getQueryBuilder(ctx).WithUpdateOperation(operation).WithUpdateBackup(backupToWrite),
Expand Down Expand Up @@ -148,6 +149,7 @@ func TBOperationHandler(
operation.SetState(types.OperationStateError)
operation.SetMessage(ydbOpResponse.IssueString())
}
backupToWrite.Message = operation.GetMessage()
}
case types.OperationStateStartCancelling:
{
Expand All @@ -156,6 +158,7 @@ func TBOperationHandler(
return err
}
backupToWrite.Status = types.BackupStateError
backupToWrite.Message = operation.GetMessage()
backupToWrite.AuditInfo.CompletedAt = operation.GetAudit().CompletedAt
return db.ExecuteUpsert(
ctx, getQueryBuilder(ctx).WithUpdateOperation(operation).WithUpdateBackup(backupToWrite),
Expand All @@ -170,6 +173,7 @@ func TBOperationHandler(
operation.SetState(types.OperationStateError)
operation.SetMessage("Operation deadline exceeded")
operation.GetAudit().CompletedAt = now
backupToWrite.Message = operation.GetMessage()
return db.ExecuteUpsert(
ctx, getQueryBuilder(ctx).WithUpdateOperation(operation).WithUpdateBackup(backupToWrite),
)
Expand All @@ -196,6 +200,7 @@ func TBOperationHandler(
operation.SetState(types.OperationStateError)
operation.SetMessage(ydbOpResponse.IssueString())
}
backupToWrite.Message = operation.GetMessage()
}
default:
return fmt.Errorf("unexpected operation state %s", tb.State)
Expand Down

0 comments on commit 8cac8de

Please sign in to comment.