Display results from Piscal processing
Error handling for Piscal processing
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using LeafWeb.Web.ViewModels.LeafOutput;
|
||||
|
||||
namespace LeafWeb.Web.Controllers
|
||||
{
|
||||
@@ -6,7 +8,11 @@ namespace LeafWeb.Web.Controllers
|
||||
{
|
||||
public ActionResult Index()
|
||||
{
|
||||
var viewModel = DataService.GetLeafOutputFiles();
|
||||
var viewModel =
|
||||
DataService.GetLeafInputFiles()
|
||||
.OrderByDescending(f => f.Id)
|
||||
.ToList()
|
||||
.Select(f => new LeafOutputViewModel(f));
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
|
||||
<rules>
|
||||
<logger name="Hangfire.*" minlevel="Debug" maxlevel="Info" final="true"/>
|
||||
<logger name="*" minlevel="Debug" writeTo="debugLogger"/>
|
||||
<logger name="*" minlevel="Trace" writeTo="debugLogger"/>
|
||||
<logger name="*" minlevel="Error" writeTo="exceptionLogger" />
|
||||
</rules>
|
||||
</nlog>
|
||||
@@ -31,13 +31,18 @@ namespace LeafWeb.Web.Services
|
||||
{
|
||||
logger.Trace("ProcessQueue entered");
|
||||
|
||||
ProcessRunning(logger);
|
||||
try
|
||||
{
|
||||
ProcessRunning(logger);
|
||||
|
||||
ProcessQueue(logger);
|
||||
ProcessQueue(logger);
|
||||
}
|
||||
finally
|
||||
{
|
||||
logger.Trace("ProcessQueue exit");
|
||||
|
||||
logger.Trace("ProcessQueue completed");
|
||||
|
||||
Monitor.Exit(ProcessQueueLock);
|
||||
Monitor.Exit(ProcessQueueLock);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -54,14 +59,25 @@ namespace LeafWeb.Web.Services
|
||||
var queuedFile =
|
||||
_dataService
|
||||
.GetLeafInputFiles(LeafInputStatusType.Queued)
|
||||
.OrderBy(l => l.Id)
|
||||
.OrderBy(l => l.StatusHistory.Min(sh => sh.DateTime))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (queuedFile == null)
|
||||
return;
|
||||
|
||||
logger.Info("LeafInputFile: {0}, Start", queuedFile.Id);
|
||||
_piscalService.Run(queuedFile);
|
||||
try
|
||||
{
|
||||
_piscalService.Run(queuedFile);
|
||||
}
|
||||
catch (PiscalClientException ex)
|
||||
{
|
||||
logger.Error("LeafInputFile: {0}, ProcessQueue Exception: {1}", queuedFile.Id, ex.Message);
|
||||
_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Error, "Error occurred submitting LeafInput");
|
||||
|
||||
// TODO: re-queue
|
||||
//_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Queued, "Re-queuing LeafInput");
|
||||
}
|
||||
_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Running);
|
||||
}
|
||||
|
||||
@@ -71,33 +87,55 @@ namespace LeafWeb.Web.Services
|
||||
foreach (var file in runningLeafInputFiles)
|
||||
{
|
||||
var status = _piscalService.GetStatus(file);
|
||||
switch (status)
|
||||
try
|
||||
{
|
||||
case PiscalStatus.Running:
|
||||
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.RetrieveOutputFiles(file).ToList();
|
||||
foreach (var outputFile in leafOutputFiles)
|
||||
_dataService.AddLeafOutputFile(outputFile);
|
||||
switch (status)
|
||||
{
|
||||
case PiscalStatus.Running:
|
||||
logger.Trace("LeafInputFile: {0}, Running", file.Id);
|
||||
// continue running
|
||||
break;
|
||||
|
||||
logger.Info("LeafInputFile: {0}, output files: {1}", file.Id,
|
||||
string.Join(", ", leafOutputFiles.Select(o => o.Filename)));
|
||||
case PiscalStatus.Success:
|
||||
logger.Info("LeafInputFile: {0}, Success", file.Id);
|
||||
// collect the leaf output
|
||||
var leafOutputFiles = _piscalService.RetrieveOutputFiles(file).ToList();
|
||||
foreach (var outputFile in leafOutputFiles)
|
||||
_dataService.AddLeafOutputFile(outputFile);
|
||||
|
||||
// update db
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Complete);
|
||||
logger.Info("LeafInputFile: {0}, output files: {1}", file.Id,
|
||||
string.Join(", ", leafOutputFiles.Select(o => o.Filename)));
|
||||
|
||||
// remove working data from the server
|
||||
logger.Info("LeafInputFile: {0}, cleanup", file.Id);
|
||||
_piscalService.Cleanup(file);
|
||||
break;
|
||||
case PiscalStatus.Error:
|
||||
logger.Info("LeafInputFile: {0}, error", file.Id);
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Error);
|
||||
break;
|
||||
// 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.NotStarted:
|
||||
logger.Warn("LeafInputFile: {0}, Not Started, re-queueing", file.Id);
|
||||
// if it's not started, try to requeue the process - unusual state
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Queued);
|
||||
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.SetLeafInputFileStatus(file, LeafInputStatusType.Error, errorMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (PiscalClientException ex)
|
||||
{
|
||||
logger.Error("LeafInputFile: {0}, ProcessRunning Exception: {1}", file.Id, ex.Message);
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Error, "Error occurred processing LeafInput");
|
||||
|
||||
// TODO: re-queue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,12 @@ namespace LeafWeb.Web.Services
|
||||
}
|
||||
}
|
||||
|
||||
public string GetErrorMessage(LeafInputFile leafInputFile)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
return _piscalClient.GetErrorMessage(inputFile);
|
||||
}
|
||||
|
||||
public void Cleanup(LeafInputFile leafInputFile)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using LeafWeb.Core.Entities;
|
||||
|
||||
namespace LeafWeb.Web.ViewModels.LeafOutput
|
||||
{
|
||||
@@ -10,7 +11,9 @@ namespace LeafWeb.Web.ViewModels.LeafOutput
|
||||
public int LeafInputFileId { get; set; }
|
||||
public string LeafInputFilename { get; set; }
|
||||
public string CurrentStatus { get; set; }
|
||||
public string[] ErrorMessages { get; set; }
|
||||
public string[] LeafOutputFilenames { get; set; }
|
||||
public string LeafInputName { get; set; }
|
||||
public string LeafInputIdentifier { get; set; }
|
||||
public string LeafInputSiteId { get; set; }
|
||||
public string LeafInputPhotosynthesisType { get; set; }
|
||||
@@ -20,19 +23,33 @@ namespace LeafWeb.Web.ViewModels.LeafOutput
|
||||
var config =
|
||||
new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Core.Entities.LeafInputFile, LeafOutputViewModel>()
|
||||
cfg.CreateMap<LeafInputFile, LeafOutputViewModel>()
|
||||
.ForMember(dest => dest.LeafInputFileId, opt => opt.MapFrom(src => src.Id))
|
||||
.ForMember(dest => dest.LeafInputFilename, opt => opt.MapFrom(src => src.Filename))
|
||||
.ForMember(dest => dest.LeafOutputFilenames,
|
||||
opt => opt.ResolveUsing(file => file.LeafOutputFiles?.Select(o => o.Filename).ToArray() ?? new string[] {}))
|
||||
opt => opt.ResolveUsing(
|
||||
file =>
|
||||
file.LeafOutputFiles?
|
||||
.Select(o => o.Filename)
|
||||
.ToArray()
|
||||
?? new string[] {}))
|
||||
.ForMember(dest => dest.LeafInputName, opt => opt.MapFrom(src => src.LeafInput.Name))
|
||||
.ForMember(dest => dest.LeafInputIdentifier, opt => opt.MapFrom(src => src.LeafInput.Identifier))
|
||||
.ForMember(dest => dest.LeafInputSiteId, opt => opt.MapFrom(src => src.LeafInput.SiteId))
|
||||
.ForMember(dest => dest.LeafInputPhotosynthesisType, opt => opt.MapFrom(src => src.LeafInput.PhotosynthesisType.Name));
|
||||
.ForMember(dest => dest.LeafInputPhotosynthesisType, opt => opt.MapFrom(src => src.LeafInput.PhotosynthesisType.Name))
|
||||
.ForMember(dest => dest.ErrorMessages,
|
||||
opt => opt.ResolveUsing(
|
||||
src =>
|
||||
src.StatusHistory?
|
||||
.Where(sh => sh.Status == LeafInputStatusType.Error)
|
||||
.Select(sh => sh.Description)
|
||||
.ToArray()
|
||||
?? new string[] {}));
|
||||
});
|
||||
Mapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
public LeafOutputViewModel(Core.Entities.LeafInputFile leafInput)
|
||||
public LeafOutputViewModel(LeafInputFile leafInput)
|
||||
{
|
||||
Mapper.Map(leafInput, this);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
@model LeafWeb.Web.ViewModels.LeafOutput.LeafOutputViewModel
|
||||
@model IEnumerable<LeafWeb.Web.ViewModels.LeafOutput.LeafOutputViewModel>
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Users";
|
||||
ViewBag.Title = "Results";
|
||||
var grid = new WebGrid(Model, rowsPerPage: 45);
|
||||
}
|
||||
|
||||
<h1>EDO Results</h1>
|
||||
<h1>Results</h1>
|
||||
|
||||
<div class="row">
|
||||
|
||||
</div>
|
||||
@grid.GetHtml(columns:
|
||||
grid.Columns(
|
||||
grid.Column("LeafInputIdentifier", "Identifier"),
|
||||
grid.Column("LeafInputSiteId", "Site Id"),
|
||||
grid.Column("LeafInputFilename", "Filename"),
|
||||
grid.Column("LeafInputName", "Submitted By"),
|
||||
grid.Column("CurrentStatus", "Status")
|
||||
),
|
||||
htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed" }
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user