From 064b86a37b95849088063db987ed7b4b3944e2f5 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Wed, 13 Apr 2016 10:48:32 -0400 Subject: [PATCH] Add debug tracing, email cleanup --- Web/App_Start/RouteConfig.cs | 2 +- Web/Services/EmailNotificationService.cs | 25 ++++++++++++++++++------ Web/Services/PiscalQueueManager.cs | 16 ++++++++++++--- Web/Views/LeafInput/Index.cshtml | 5 +++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Web/App_Start/RouteConfig.cs b/Web/App_Start/RouteConfig.cs index 2d681f3..a4e14a3 100644 --- a/Web/App_Start/RouteConfig.cs +++ b/Web/App_Start/RouteConfig.cs @@ -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 } ); } } diff --git a/Web/Services/EmailNotificationService.cs b/Web/Services/EmailNotificationService.cs index af618f0..8897ffd 100644 --- a/Web/Services/EmailNotificationService.cs +++ b/Web/Services/EmailNotificationService.cs @@ -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 diff --git a/Web/Services/PiscalQueueManager.cs b/Web/Services/PiscalQueueManager.cs index 40eae92..60bee92 100644 --- a/Web/Services/PiscalQueueManager.cs +++ b/Web/Services/PiscalQueueManager.cs @@ -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 diff --git a/Web/Views/LeafInput/Index.cshtml b/Web/Views/LeafInput/Index.cshtml index 8d644fd..a89bae1 100644 --- a/Web/Views/LeafInput/Index.cshtml +++ b/Web/Views/LeafInput/Index.cshtml @@ -1,4 +1,9 @@ @model LeafWeb.Web.ViewModels.LeafInput.CreateViewModel + +@{ + ViewBag.Title = "Submit Data"; +} + @section Styles { @Styles.Render("~/backload/blueimp/bootstrap/BasicPlusUI/css")