Cleanup data after complete for Piscal Service
This commit is contained in:
@@ -7,5 +7,6 @@ namespace LeafWeb.Core.Remote
|
||||
void RunLeafInputFile(PiscalLeafInputFile file);
|
||||
PiscalStatus GetLeafInputFileStatus(PiscalLeafInputFile file);
|
||||
IEnumerable<PiscalLeafOutputFile> RetrieveLeafOutput(PiscalLeafInputFile file);
|
||||
void CleanupLeafProcess(PiscalLeafInputFile file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,27 +21,27 @@ namespace LeafWeb.Web.Services
|
||||
|
||||
public PiscalQueueManager() : this(new DataService(), new PiscalService()) {}
|
||||
|
||||
private static readonly object Lock = new object();
|
||||
private static readonly object ProcessQueueLock = new object();
|
||||
|
||||
public void ProcessQueue()
|
||||
{
|
||||
var logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
if (Monitor.TryEnter(Lock))
|
||||
if (Monitor.TryEnter(ProcessQueueLock))
|
||||
{
|
||||
logger.Trace("Process entered");
|
||||
logger.Trace("ProcessQueue entered");
|
||||
|
||||
ProcessRunning(logger);
|
||||
|
||||
ProcessQueue(logger);
|
||||
|
||||
logger.Trace("Process completed");
|
||||
logger.Trace("ProcessQueue completed");
|
||||
|
||||
Monitor.Exit(Lock);
|
||||
Monitor.Exit(ProcessQueueLock);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Trace("Process locked, queue already processing");
|
||||
logger.Trace("ProcessQueue locked, queue already processing");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace LeafWeb.Web.Services
|
||||
return;
|
||||
|
||||
logger.Info("LeafInputFile: {0}, Start", queuedFile.Id);
|
||||
_piscalService.RunLeafInputFile(queuedFile);
|
||||
_piscalService.Run(queuedFile);
|
||||
_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Running);
|
||||
}
|
||||
|
||||
@@ -70,27 +70,32 @@ namespace LeafWeb.Web.Services
|
||||
var runningLeafInputFiles = _dataService.GetLeafInputFiles(LeafInputStatusType.Running).ToList();
|
||||
foreach (var file in runningLeafInputFiles)
|
||||
{
|
||||
var status = _piscalService.GetLeafInputFileStatus(file);
|
||||
var status = _piscalService.GetStatus(file);
|
||||
switch (status)
|
||||
{
|
||||
case PiscalStatus.Running:
|
||||
logger.Debug("LeafInputFile: {0}, {1}", file.Id, status);
|
||||
logger.Trace("LeafInputFile: {0}, {1}", file.Id, status);
|
||||
// continue running
|
||||
break;
|
||||
case PiscalStatus.Success:
|
||||
logger.Info("LeafInputFile: {0}, {1}", file.Id, status);
|
||||
// collect the leaf output
|
||||
var leafOutputFiles = _piscalService.RetrieveLeafOutputFile(file).ToList();
|
||||
var leafOutputFiles = _piscalService.RetrieveOutputFiles(file).ToList();
|
||||
foreach (var outputFile in leafOutputFiles)
|
||||
{
|
||||
_dataService.AddLeafOutputFile(outputFile);
|
||||
}
|
||||
|
||||
logger.Info("LeafInputFile: {0}, output files: {1}", file.Id,
|
||||
string.Join(", ", leafOutputFiles.Select(o => o.Filename)));
|
||||
|
||||
// update db
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Complete);
|
||||
|
||||
// remove working data from the server
|
||||
logger.Info("LeafInputFile: {0}, cleanup", file.Id);
|
||||
_piscalService.Cleanup(file);
|
||||
break;
|
||||
case PiscalStatus.Error:
|
||||
logger.Error("LeafInputFile: {0}", file.Id);
|
||||
logger.Info("LeafInputFile: {0}, error", file.Id);
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Error);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -18,19 +18,19 @@ namespace LeafWeb.Web.Services
|
||||
{
|
||||
}
|
||||
|
||||
public void RunLeafInputFile(LeafInputFile leafInputFile)
|
||||
public void Run(LeafInputFile leafInputFile)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
_piscalClient.RunLeafInputFile(inputFile);
|
||||
}
|
||||
|
||||
public PiscalStatus GetLeafInputFileStatus(LeafInputFile leafInputFile)
|
||||
public PiscalStatus GetStatus(LeafInputFile leafInputFile)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
return _piscalClient.GetLeafInputFileStatus(inputFile);
|
||||
}
|
||||
|
||||
public IEnumerable<LeafOutputFile> RetrieveLeafOutputFile(LeafInputFile leafInputFile)
|
||||
public IEnumerable<LeafOutputFile> RetrieveOutputFiles(LeafInputFile leafInputFile)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
var piscalLeafOutputFiles = _piscalClient.RetrieveLeafOutput(inputFile);
|
||||
@@ -41,5 +41,11 @@ namespace LeafWeb.Web.Services
|
||||
yield return leafOutputFile;
|
||||
}
|
||||
}
|
||||
|
||||
public void Cleanup(LeafInputFile leafInputFile)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
_piscalClient.CleanupLeafProcess(inputFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user