Cleanup data after complete for Piscal Service
This commit is contained in:
@@ -14,6 +14,10 @@ namespace LeafWeb.Core.Remote
|
||||
private const string RemoteScriptPath = BaseDirectory + "/piscal_manager.sh";
|
||||
private readonly PasswordConnectionInfo _connectionInfo;
|
||||
|
||||
private const string StatusSuccess = "success";
|
||||
private const string StatusRunning = "running";
|
||||
private const string StatusError = "error";
|
||||
|
||||
public PiscalSshClient(string connectionString)
|
||||
{
|
||||
var conn = new DbConnectionStringBuilder {ConnectionString = connectionString};
|
||||
@@ -70,9 +74,9 @@ namespace LeafWeb.Core.Remote
|
||||
|
||||
switch (statusRaw[0])
|
||||
{
|
||||
case "running":
|
||||
case StatusRunning:
|
||||
return PiscalStatus.Running;
|
||||
case "success":
|
||||
case StatusSuccess:
|
||||
return PiscalStatus.Success;
|
||||
default:
|
||||
return PiscalStatus.Error;
|
||||
@@ -106,7 +110,7 @@ namespace LeafWeb.Core.Remote
|
||||
{
|
||||
// get output files
|
||||
var status = GetLeafInputStatusRaw(file);
|
||||
if (status[0] != "success")
|
||||
if (status[0] != StatusSuccess)
|
||||
throw new PiscalClientException("output not available, status is " + status[0]);
|
||||
|
||||
var filePaths = status.Skip(1);
|
||||
@@ -132,5 +136,24 @@ namespace LeafWeb.Core.Remote
|
||||
scp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public void CleanupLeafProcess(PiscalLeafInputFile file)
|
||||
{
|
||||
var status = GetLeafInputStatusRaw(file);
|
||||
if (status[0] == StatusRunning)
|
||||
throw new PiscalClientException("Trying to cleanup a running process");
|
||||
|
||||
using (var ssh = GetSshClient())
|
||||
{
|
||||
ssh.Connect();
|
||||
var commandText = $"{RemoteScriptPath} -d {file.DirectoryName} -c";
|
||||
var command = ssh.CreateCommand(commandText);
|
||||
command.Execute();
|
||||
ssh.Disconnect();
|
||||
|
||||
if (command.ExitStatus != 0)
|
||||
throw new PiscalClientException(command.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user