Add debug tracing, email cleanup

This commit is contained in:
2016-04-13 10:48:32 -04:00
parent 123af4f44d
commit 064b86a37b
4 changed files with 38 additions and 10 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ namespace LeafWeb.Web.App_Start
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Pages", action = "Index", id = UrlParameter.Optional }
defaults: new { controller = "LeafInput", action = "Index", id = UrlParameter.Optional }
);
}
}
+19 -6
View File
@@ -59,13 +59,12 @@ namespace LeafWeb.Web.Services
leafInput.OutputFiles
select Tuple.Create(outputFile, new MemoryStream(outputFile.Contents))).ToList();
var body = $"Your leaf analysis job, {leafInput.Identifier}, has completed." + Environment.NewLine;
if (leafInput.OutputWarningMessage != null)
body += "The following warning message was generated."
+ Environment.NewLine + Environment.NewLine
+ leafInput.OutputWarningMessage.Contents.GetString()
+ Environment.NewLine;
var body = $"Your leaf analysis job, {leafInput.Identifier}, has completed. ";
body += FormatWarningMessage(leafInput);
body += "Please see the attached results.";
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb results", body);
try
@@ -95,10 +94,24 @@ namespace LeafWeb.Web.Services
+ errorMessage
+ Environment.NewLine + Environment.NewLine
+ "You will need to correct your input and resubmit.";
body += FormatWarningMessage(leafInput);
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb processing error", body);
SendMessage(message);
}
private string FormatWarningMessage(LeafInput leafInput)
{
if (leafInput.OutputWarningMessage != null)
return Environment.NewLine + Environment.NewLine
+ "The following warning message was generated."
+ Environment.NewLine + Environment.NewLine
+ leafInput.OutputWarningMessage.Contents.GetString()
+ Environment.NewLine;
return string.Empty;
}
private void SendMessage(MailMessage mailMessage)
{
try
+13 -3
View File
@@ -57,7 +57,10 @@ namespace LeafWeb.Web.Services
{
var runningLeafInputs = _dataService.GetLeafInputs(LeafInputStatusType.Running).ToList();
if (runningLeafInputs.Any())
{
logger.Trace("Leaf input currently running , don't enqueue any new");
return;
}
var pending =
_dataService
@@ -66,7 +69,10 @@ namespace LeafWeb.Web.Services
.FirstOrDefault();
if (pending == null)
{
logger.Trace("No pending leaf input");
return;
}
logger.Info("LeafInputFile: {0}, Start", pending.Id);
try
@@ -83,6 +89,7 @@ namespace LeafWeb.Web.Services
// TODO: re-queue?
//_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Queued, "Re-queuing LeafInput");
}
logger.Trace("LeafInputFile: {0}, Set Pending", pending.Id);
_dataService.SetLeafInputStatus(pending, LeafInputStatusType.Running);
}
@@ -98,7 +105,7 @@ namespace LeafWeb.Web.Services
{
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
// if it's not started, try to requeue the process - this is unusual state
_dataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Pending);
break;
@@ -111,6 +118,8 @@ namespace LeafWeb.Web.Services
logger.Info("LeafInputFile: {0}, Complete", leafInput.Id);
// collect the leaf output
var leafOutputFiles = _piscalService.RetrieveOutputFiles(leafInput).ToList();
logger.Trace("LeafInputFile: {0}, saving output files", leafInput.Id);
foreach (var outputFile in leafOutputFiles)
_dataService.AddLeafOutputFile(outputFile);
@@ -118,6 +127,7 @@ namespace LeafWeb.Web.Services
string.Join(", ", leafOutputFiles.Select(o => o.Filename)));
// update db
logger.Trace("LeafInputFile: {0}, Set Complete", leafInput.Id);
_dataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Complete);
BackgroundJob.Enqueue(() => _emailService.SendLeafWebComplete(leafInput.Id));
@@ -128,9 +138,9 @@ namespace LeafWeb.Web.Services
break;
}
}
catch (PiscalClientException ex)
catch (Exception ex)
{
logger.Error("LeafInputFile: {0}, ProcessRunning Exception: {1}", leafInput.Id, ex.Message);
logger.Error("LeafInputFile: {0}, ProcessRunning Exception: {1}\r\n{2}\r\n{3}", leafInput.Id, ex.Message, ex.InnerException, ex.StackTrace);
_dataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Exception, "Error occurred processing LeafInput", ex.Message);
// TODO: Send email
+5
View File
@@ -1,4 +1,9 @@
@model LeafWeb.Web.ViewModels.LeafInput.CreateViewModel
@{
ViewBag.Title = "Submit Data";
}
@section Styles
{
@Styles.Render("~/backload/blueimp/bootstrap/BasicPlusUI/css")