Piscal processing work

This commit is contained in:
2016-04-06 13:00:12 -04:00
parent 214199fed5
commit 151f17943f
18 changed files with 141 additions and 127 deletions
+27 -37
View File
@@ -76,9 +76,11 @@ namespace LeafWeb.Web.Services
catch (PiscalClientException ex)
{
logger.Error("LeafInputFile: {0}, ProcessQueue Exception: {1}", pending.Id, ex.Message);
_dataService.SetLeafInputStatus(pending, LeafInputStatusType.Error, "Error occurred submitting LeafInput");
_dataService.SetLeafInputStatus(pending, LeafInputStatusType.Exception, "Error occurred starting LeafInput", ex.Message);
logger.Info("LeafInputFile: {0}, Cleanup", pending.Id);
_piscalService.Cleanup(pending);
// TODO: re-queue
// TODO: re-queue?
//_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Queued, "Re-queuing LeafInput");
}
_dataService.SetLeafInputStatus(pending, LeafInputStatusType.Running);
@@ -87,66 +89,54 @@ namespace LeafWeb.Web.Services
private void ProcessRunning(ILogger logger)
{
var running = _dataService.GetLeafInputs(LeafInputStatusType.Running).ToList();
foreach (var file in running)
foreach (var leafInput in running)
{
var status = _piscalService.GetStatus(file);
try
{
var status = _piscalService.GetStatus(leafInput);
switch (status)
{
case PiscalStatus.NotStarted:
logger.Warn("LeafInputFile: {0}, Not Started, re-queueing", leafInput.Id);
// if it's not started, try to requeue the process - unusual state
_dataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Pending);
break;
case PiscalStatus.Running:
logger.Trace("LeafInputFile: {0}, Running", file.Id);
logger.Trace("LeafInputFile: {0}, Running", leafInput.Id);
// continue running
break;
case PiscalStatus.Success:
logger.Info("LeafInputFile: {0}, Success", file.Id);
case PiscalStatus.Complete:
logger.Info("LeafInputFile: {0}, Complete", leafInput.Id);
// collect the leaf output
var leafOutputFiles = _piscalService.RetrieveOutputFiles(file).ToList();
var leafOutputFiles = _piscalService.RetrieveOutputFiles(leafInput).ToList();
foreach (var outputFile in leafOutputFiles)
_dataService.AddLeafOutputFile(outputFile);
logger.Info("LeafInputFile: {0}, output files: {1}", file.Id,
logger.Info("LeafInputFile: {0}, output files: {1}", leafInput.Id,
string.Join(", ", leafOutputFiles.Select(o => o.Filename)));
// update db
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Complete);
_dataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Complete);
BackgroundJob.Enqueue(() => _emailService.SendLeafWebSuccess(file.Id));
BackgroundJob.Enqueue(() => _emailService.SendLeafWebComplete(leafInput.Id));
// remove working data from the server
logger.Info("LeafInputFile: {0}, Cleanup", file.Id);
_piscalService.Cleanup(file);
break;
case PiscalStatus.NotStarted:
logger.Warn("LeafInputFile: {0}, Not Started, re-queueing", file.Id);
// if it's not started, try to requeue the process - unusual state
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Pending);
break;
case PiscalStatus.Error:
logger.Info("LeafInputFile: {0}, Error", file.Id);
var errorMessage = _piscalService.GetErrorMessage(file);
logger.Info("LeafInputFile: {0}, Error Message: {1}", file.Id, errorMessage);
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Error, errorMessage);
BackgroundJob.Enqueue(() => _emailService.SendLeafWebError(file.Id, errorMessage));
// remove working data from the server
logger.Info("LeafInputFile: {0}, Cleanup", file.Id);
_piscalService.Cleanup(file);
logger.Info("LeafInputFile: {0}, Cleanup", leafInput.Id);
_piscalService.Cleanup(leafInput);
break;
}
}
catch (PiscalClientException ex)
{
logger.Error("LeafInputFile: {0}, ProcessRunning Exception: {1}", file.Id, ex.Message);
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Error, "Error occurred processing LeafInput");
logger.Error("LeafInputFile: {0}, ProcessRunning Exception: {1}", leafInput.Id, ex.Message);
_dataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Exception, "Error occurred processing LeafInput", ex.Message);
// TODO: re-queue
// TODO: Send email
logger.Info("LeafInputFile: {0}, Cleanup", leafInput.Id);
_piscalService.Cleanup(leafInput);
// TODO: re-queue ?
}
}
}