Fixed server delete

This commit is contained in:
Marcel Baumgartner
2023-06-26 22:50:45 +02:00
parent fe1f4412d8
commit d60f8fc905

View File

@@ -119,7 +119,8 @@ public class ServerService
var backup = new ServerBackup() var backup = new ServerBackup()
{ {
Name = $"Created at {DateTimeService.GetCurrent().ToShortDateString()} {DateTimeService.GetCurrent().ToShortTimeString()}", Name =
$"Created at {DateTimeService.GetCurrent().ToShortDateString()} {DateTimeService.GetCurrent().ToShortTimeString()}",
Uuid = Guid.NewGuid(), Uuid = Guid.NewGuid(),
CreatedAt = DateTimeService.GetCurrent(), CreatedAt = DateTimeService.GetCurrent(),
Created = false Created = false
@@ -185,8 +186,15 @@ public class ServerService
try try
{ {
await WingsApiHelper.Delete(serverData.Node, $"api/servers/{serverData.Uuid}/backup/{serverBackup.Uuid}", await new Retry()
.Times(3)
.At(x => x.Message.Contains("A task was canceled"))
.Call(async () =>
{
await WingsApiHelper.Delete(serverData.Node,
$"api/servers/{serverData.Uuid}/backup/{serverBackup.Uuid}",
null); null);
});
} }
catch (WingsException e) catch (WingsException e)
{ {
@@ -267,7 +275,8 @@ public class ServerService
freeAllocations = NodeAllocationRepository freeAllocations = NodeAllocationRepository
.Get() .Get()
.FromSqlRaw($"SELECT * FROM `NodeAllocations` WHERE ServerId IS NULL AND NodeId={node.Id} LIMIT {allocations}") .FromSqlRaw(
$"SELECT * FROM `NodeAllocations` WHERE ServerId IS NULL AND NodeId={node.Id} LIMIT {allocations}")
.ToArray(); .ToArray();
} }
catch (Exception) catch (Exception)
@@ -386,8 +395,6 @@ public class ServerService
public async Task Delete(Server s) public async Task Delete(Server s)
{ {
throw new DisplayException("Deleting servers is currently disabled");
var backups = await GetBackups(s); var backups = await GetBackups(s);
foreach (var backup in backups) foreach (var backup in backups)
@@ -408,7 +415,21 @@ public class ServerService
.Include(x => x.Node) .Include(x => x.Node)
.First(x => x.Id == s.Id); .First(x => x.Id == s.Id);
try
{
await new Retry()
.Times(3)
.At(x => x.Message.Contains("A task was canceled"))
.Call(async () =>
{
await WingsApiHelper.Delete(server.Node, $"api/servers/{server.Uuid}", null); await WingsApiHelper.Delete(server.Node, $"api/servers/{server.Uuid}", null);
});
}
catch (WingsException e)
{
if (e.StatusCode != 404)
throw;
}
foreach (var variable in server.Variables.ToArray()) foreach (var variable in server.Variables.ToArray())
{ {