Add cancel

This commit is contained in:
2017-01-26 08:36:54 -05:00
parent 295b40bed8
commit 4338b4fee5
30 changed files with 333 additions and 62 deletions
+18 -6
View File
@@ -21,14 +21,26 @@ namespace LeafWeb.Core.Entities
public LeafInputStatusType CurrentStatus { get; set; }
public virtual ICollection<LeafInputStatus> StatusHistory { get; set; }
public bool IsInProgress => CurrentStatus == LeafInputStatusType.Starting
|| CurrentStatus == LeafInputStatusType.Running
|| CurrentStatus == LeafInputStatusType.Finishing;
public bool IsComplete => CurrentStatus == LeafInputStatusType.Complete;
public bool IsDeletable => !IsInProgress;
public bool IsPending => CurrentStatus == LeafInputStatusType.Pending;
public bool IsStarting => CurrentStatus == LeafInputStatusType.Starting;
public bool IsRunning => CurrentStatus == LeafInputStatusType.Running;
public bool IsFinishing => CurrentStatus == LeafInputStatusType.Finishing;
public bool IsComplete => CurrentStatus == LeafInputStatusType.Complete;
public bool IsException => CurrentStatus == LeafInputStatusType.Exception;
public bool IsCancelPending => CurrentStatus == LeafInputStatusType.CancelPending;
public bool IsCancelling => CurrentStatus == LeafInputStatusType.Cancelling;
public bool IsCancelled => CurrentStatus == LeafInputStatusType.Cancelled;
public bool IsInProgress => IsStarting
|| IsRunning
|| IsFinishing
|| IsCancelPending
|| IsCancelling;
public bool IsDeletable => !IsInProgress;
public bool HasOutputFiles => OutputFiles.Any();
public bool IsCancellable =>
IsRunning
|| IsPending;
[Required(ErrorMessage = "Name required")]
public string Name { get; set; }
+4 -1
View File
@@ -7,6 +7,9 @@ namespace LeafWeb.Core.Entities
Running = 2,
Finishing = 3,
Complete = 4,
Exception = 5
Exception = 5,
CancelPending = 6,
Cancelling = 7,
Cancelled = 8
}
}
+1
View File
@@ -8,6 +8,7 @@ namespace LeafWeb.Core.Remote
void RunLeafInput(PiscalLeafInput leafInput);
PiscalStatus GetLeafInputStatus(PiscalLeafInput leafInput);
IEnumerable<PiscalLeafOutputFile> RetrieveLeafOutput(PiscalLeafInput leafInput);
void KillLeafProcess(PiscalLeafInput leafInput);
void CleanupLeafProcess(PiscalLeafInput leafInput);
}
}
+14
View File
@@ -1,13 +1,27 @@
using System;
using LeafWeb.Core.Utility;
using Renci.SshNet;
namespace LeafWeb.Core.Remote
{
public class PiscalClientException : Exception
{
public int LeafInputId { get; private set; }
public string CommandText { get; private set; }
public PiscalClientException(int leafInputId, string error) : base(error)
{
LeafInputId = leafInputId;
}
public PiscalClientException(int leafInputId, SshCommand command) : base(
!string.IsNullOrEmpty(command.Error)
? command.Error.TrimEndNewLine()
: command.Result.TrimEndNewLine()
)
{
LeafInputId = leafInputId;
CommandText = command.CommandText;
}
}
}
+19 -4
View File
@@ -115,7 +115,7 @@ namespace LeafWeb.Core.Remote
Disconnect(leafInput, ssh);
if (command.ExitStatus != 0)
throw new PiscalClientException(leafInput.LeafInputId, command.Error.TrimEndNewLine());
throw new PiscalClientException(leafInput.LeafInputId, command);
var result = command.Result.TrimEndNewLine();
if (result == "started")
@@ -154,7 +154,7 @@ namespace LeafWeb.Core.Remote
Disconnect(leafInput, ssh);
if (command.ExitStatus != 0)
throw new PiscalClientException(leafInput.LeafInputId, command.Error.TrimEndNewLine());
throw new PiscalClientException(leafInput.LeafInputId, command);
return command.Result
.SplitNewLine()
@@ -203,7 +203,22 @@ namespace LeafWeb.Core.Remote
Disconnect(leafInput, scp);
}
}
public void KillLeafProcess(PiscalLeafInput leafInput)
{
using (var ssh = GetSshClient())
{
Connect(leafInput, ssh);
var commandText = $"{RemoteScriptPath} -d {leafInput.PiscalDirectoryName} -k";
var command = ssh.CreateCommand(commandText);
command.Execute();
Disconnect(leafInput, ssh);
if (command.ExitStatus != 0)
throw new PiscalClientException(leafInput.LeafInputId, command);
}
}
public void CleanupLeafProcess(PiscalLeafInput leafInput)
{
using (var ssh = GetSshClient())
@@ -215,7 +230,7 @@ namespace LeafWeb.Core.Remote
Disconnect(leafInput, ssh);
if (command.ExitStatus != 0)
throw new PiscalClientException(leafInput.LeafInputId, command.Error.TrimEndNewLine());
throw new PiscalClientException(leafInput.LeafInputId, command);
}
}
}