mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-04-22 19:15:48 +02:00
Add timeouts while waiting for server output during backups
This commit is contained in:
parent
f7f08ec55c
commit
875fd9a766
Agent/Phantom.Agent.Services/Backups
Common/Phantom.Common.Data/Backups
@ -67,6 +67,10 @@ sealed class BackupManager : IDisposable {
|
||||
resultBuilder.Kind = BackupCreationResultKind.BackupCancelled;
|
||||
logger.Warning("Backup creation was cancelled.");
|
||||
return null;
|
||||
} catch (TimeoutException) {
|
||||
resultBuilder.Kind = BackupCreationResultKind.BackupTimedOut;
|
||||
logger.Warning("Backup creation timed out.");
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
resultBuilder.Kind = BackupCreationResultKind.UnknownError;
|
||||
logger.Error(e, "Caught exception while creating an instance backup.");
|
||||
@ -76,6 +80,9 @@ sealed class BackupManager : IDisposable {
|
||||
await dispatcher.EnableAutomaticSaving();
|
||||
} catch (OperationCanceledException) {
|
||||
// Ignore.
|
||||
} catch (TimeoutException) {
|
||||
resultBuilder.Warnings |= BackupCreationWarnings.CouldNotRestoreAutomaticSaving;
|
||||
logger.Warning("Timed out waiting for automatic saving to be re-enabled.");
|
||||
} catch (Exception e) {
|
||||
resultBuilder.Warnings |= BackupCreationWarnings.CouldNotRestoreAutomaticSaving;
|
||||
logger.Error(e, "Caught exception while enabling automatic saving after creating an instance backup.");
|
||||
@ -120,6 +127,7 @@ sealed class BackupManager : IDisposable {
|
||||
BackupCreationResultKind.Success => "Backup created successfully.",
|
||||
BackupCreationResultKind.InstanceNotRunning => "Instance is not running.",
|
||||
BackupCreationResultKind.BackupCancelled => "Backup cancelled.",
|
||||
BackupCreationResultKind.BackupTimedOut => "Backup timed out.",
|
||||
BackupCreationResultKind.BackupAlreadyRunning => "A backup is already being created.",
|
||||
BackupCreationResultKind.BackupFileAlreadyExists => "Backup with the same name already exists.",
|
||||
BackupCreationResultKind.CouldNotCreateBackupFolder => "Could not create backup folder.",
|
||||
|
@ -32,18 +32,18 @@ sealed partial class BackupServerCommandDispatcher : IDisposable {
|
||||
|
||||
public async Task DisableAutomaticSaving() {
|
||||
await process.SendCommand(MinecraftCommand.SaveOff, cancellationToken);
|
||||
await automaticSavingDisabled.Task.WaitAsync(cancellationToken);
|
||||
await automaticSavingDisabled.Task.WaitAsync(TimeSpan.FromSeconds(30), cancellationToken);
|
||||
}
|
||||
|
||||
public async Task SaveAllChunks() {
|
||||
// TODO Try if not flushing and waiting a few seconds before flushing reduces lag.
|
||||
await process.SendCommand(MinecraftCommand.SaveAll(flush: true), cancellationToken);
|
||||
await savedTheGame.Task.WaitAsync(cancellationToken);
|
||||
await savedTheGame.Task.WaitAsync(TimeSpan.FromMinutes(1), cancellationToken);
|
||||
}
|
||||
|
||||
public async Task EnableAutomaticSaving() {
|
||||
await process.SendCommand(MinecraftCommand.SaveOn, cancellationToken);
|
||||
await automaticSavingEnabled.Task.WaitAsync(cancellationToken);
|
||||
await automaticSavingEnabled.Task.WaitAsync(TimeSpan.FromMinutes(1), cancellationToken);
|
||||
}
|
||||
|
||||
private void OnOutput(object? sender, string? line) {
|
||||
|
@ -1,15 +1,16 @@
|
||||
namespace Phantom.Common.Data.Backups;
|
||||
|
||||
public enum BackupCreationResultKind : byte {
|
||||
UnknownError,
|
||||
Success,
|
||||
InstanceNotRunning,
|
||||
BackupCancelled,
|
||||
BackupAlreadyRunning,
|
||||
BackupFileAlreadyExists,
|
||||
CouldNotCreateBackupFolder,
|
||||
CouldNotCopyWorldToTemporaryFolder,
|
||||
CouldNotCreateWorldArchive
|
||||
UnknownError = 0,
|
||||
Success = 1,
|
||||
InstanceNotRunning = 2,
|
||||
BackupTimedOut = 3,
|
||||
BackupCancelled = 4,
|
||||
BackupAlreadyRunning = 5,
|
||||
BackupFileAlreadyExists = 6,
|
||||
CouldNotCreateBackupFolder = 7,
|
||||
CouldNotCopyWorldToTemporaryFolder = 8,
|
||||
CouldNotCreateWorldArchive = 9
|
||||
}
|
||||
|
||||
public static class BackupCreationResultSummaryExtensions {
|
||||
|
Loading…
Reference in New Issue
Block a user