Cleanup data after complete for Piscal Service
This commit is contained in:
@@ -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