Piscal processing work
This commit is contained in:
@@ -34,17 +34,17 @@ namespace LeafWeb.Web.Services
|
||||
public void SendLeafWebError(int leafInputId, string errorMessage)
|
||||
{
|
||||
var leafInput = _dataService.GetLeafInput(leafInputId);
|
||||
var body = $"Your LeafWeb analysis job, {leafInput.Identifier}, encountered the following errors." + Environment.NewLine
|
||||
var body = $"Your leaf analysis job, {leafInput.Identifier}, encountered the following errors." + Environment.NewLine
|
||||
+ "You will need to correct your input and resubmit." + Environment.NewLine + Environment.NewLine
|
||||
+ errorMessage;
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb processing error", body);
|
||||
SendMessage(message);
|
||||
}
|
||||
|
||||
public void SendLeafWebSuccess(int leafInputId)
|
||||
public void SendLeafWebComplete(int leafInputId)
|
||||
{
|
||||
var leafInput = _dataService.GetLeafInput(leafInputId);
|
||||
var body = $"Your LeafWeb analysis job, {leafInput.Identifier}, has completed." + Environment.NewLine;
|
||||
var body = $"Your leaf analysis job, {leafInput.Identifier}, has completed." + Environment.NewLine;
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb results", body);
|
||||
|
||||
var fileStreams =
|
||||
|
||||
@@ -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 ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,13 +41,7 @@ namespace LeafWeb.Web.Services
|
||||
yield return leafOutputFile;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetErrorMessage(LeafInput leafInput)
|
||||
{
|
||||
var inputFile = new PiscalLeafInput(leafInput);
|
||||
return _piscalClient.GetErrorMessage(inputFile);
|
||||
}
|
||||
|
||||
|
||||
public void Cleanup(LeafInput leafInput)
|
||||
{
|
||||
var input = new PiscalLeafInput(leafInput);
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace LeafWeb.Web.ViewModels.ResultStatus
|
||||
opt => opt.ResolveUsing(
|
||||
src =>
|
||||
src.StatusHistory?
|
||||
.Where(sh => sh.Status == LeafInputStatusType.Error)
|
||||
.Where(sh => sh.Status == LeafInputStatusType.Exception)
|
||||
.Select(sh => sh.Description)
|
||||
.ToArray()
|
||||
?? new string[] {}));
|
||||
|
||||
Reference in New Issue
Block a user