Added node online check on Server create

This commit is contained in:
Moritz 2024-05-19 00:04:27 +02:00
parent 0ae9c27d93
commit ccec79cca7

View file

@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;
using MoonCore.Abstractions; using MoonCore.Abstractions;
using MoonCore.Attributes; using MoonCore.Attributes;
using MoonCore.Exceptions; using MoonCore.Exceptions;
using MoonCore.Helpers;
using MoonCore.Services; using MoonCore.Services;
using Moonlight.Core.Configuration; using Moonlight.Core.Configuration;
using Moonlight.Core.Database.Entities; using Moonlight.Core.Database.Entities;
@ -23,6 +24,8 @@ public class ServerService
public ServerBackupService Backup => ServiceProvider.GetRequiredService<ServerBackupService>(); public ServerBackupService Backup => ServiceProvider.GetRequiredService<ServerBackupService>();
public ServerScheduleService Schedule => ServiceProvider.GetRequiredService<ServerScheduleService>(); public ServerScheduleService Schedule => ServiceProvider.GetRequiredService<ServerScheduleService>();
public NodeService NodeService => ServiceProvider.GetRequiredService<NodeService>();
private readonly IServiceProvider ServiceProvider; private readonly IServiceProvider ServiceProvider;
public ServerService(IServiceProvider serviceProvider) public ServerService(IServiceProvider serviceProvider)
@ -74,6 +77,19 @@ public class ServerService
// Load node // Load node
var node = nodeRepo.Get().First(x => x.Id == form.Node.Id); var node = nodeRepo.Get().First(x => x.Id == form.Node.Id);
// Check if node is available
try
{
await NodeService.GetStatus(node);
}
catch (Exception e)
{
Logger.Warn($"Could not establish to the node with the id {node.Id}");
Logger.Warn(e);
throw new DisplayException($"Could not establish connection to the node: {e.Message}");
}
// Load user // Load user
var user = userRepo.Get().First(x => x.Id == form.Owner.Id); var user = userRepo.Get().First(x => x.Id == form.Owner.Id);