Add unresponsive status

This commit is contained in:
2018-09-12 21:23:47 -04:00
parent 91d9efa7f7
commit 62e4e156ae
13 changed files with 106 additions and 61 deletions
+26 -26
View File
@@ -125,35 +125,35 @@ namespace LeafWeb.WebCms.Services
var message = new MailMessage(_emailFromAddress, leafInput.Email, FormatSubject(SuccessSubject, leafInput), body);
SendMessage(message);
}
else
{
body += "Please see the attached results.";
//else
//{
// body += "Please see the attached results.";
var message = new MailMessage(_emailFromAddress, leafInput.Email, SuccessSubject, body);
// var message = new MailMessage(_emailFromAddress, leafInput.Email, SuccessSubject, body);
var fileStreams =
(from outputFile in
leafInput.OutputFiles
select Tuple.Create(outputFile, new MemoryStream(outputFile.FileContents.Contents))).ToList();
try
{
foreach (var fileStream in fileStreams)
{
var attachment = new Attachment(fileStream.Item2, fileStream.Item1.Filename);
message.Attachments.Add(attachment);
}
// var fileStreams =
// (from outputFile in
// leafInput.OutputFiles
// select Tuple.Create(outputFile, new MemoryStream(outputFile.FileContents.Contents))).ToList();
// try
// {
// foreach (var fileStream in fileStreams)
// {
// var attachment = new Attachment(fileStream.Item2, fileStream.Item1.Filename);
// message.Attachments.Add(attachment);
// }
SendMessage(message);
}
finally
{
// can't dispose those memory streams until the message is sent
foreach (var stream in fileStreams.Select(f => f.Item2))
{
stream.Dispose();
}
}
}
// SendMessage(message);
// }
// finally
// {
// // can't dispose those memory streams until the message is sent
// foreach (var stream in fileStreams.Select(f => f.Item2))
// {
// stream.Dispose();
// }
// }
//}
}
private void SendLeafWebError(LeafInput leafInput, string errorMessage)
@@ -1,8 +1,10 @@
using System;
using System.Configuration;
using System.Linq;
using System.Threading;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Remote;
using LeafWeb.Core.Utility;
using LeafWeb.WebCms.App_Start;
namespace LeafWeb.WebCms.Services.PiscalQueue
@@ -62,7 +64,7 @@ namespace LeafWeb.WebCms.Services.PiscalQueue
// send notification immediately
BackgroundJobEnqueueRetry<EmailNotificationService>(email => email.SendLeafWebCancelled(leafInput.Id));
}
else if (leafInput.IsRunning)
else if (leafInput.IsRunning || leafInput.IsUnresponsive)
{
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.CancelPending);
HangfireStartup.TriggerPiscalProcessQueue();
@@ -174,6 +176,7 @@ namespace LeafWeb.WebCms.Services.PiscalQueue
DataService.GetLeafInputs(
LeafInputStatusType.Starting,
LeafInputStatusType.Running,
LeafInputStatusType.Unresponsive,
LeafInputStatusType.Finishing
).ToList();
@@ -212,7 +215,7 @@ namespace LeafWeb.WebCms.Services.PiscalQueue
private void UpdateRunning()
{
var running = DataService.GetLeafInputs(LeafInputStatusType.Running).ToList();
var running = DataService.GetLeafInputs(LeafInputStatusType.Running, LeafInputStatusType.Unresponsive).ToList();
foreach (var leafInput in running)
{
try
@@ -227,12 +230,21 @@ namespace LeafWeb.WebCms.Services.PiscalQueue
PiscalWarningHandler($"LeafInput: {leafInput.Id}, {pendingToRetry}", leafInput);
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Pending, details: pendingToRetry);
break;
case PiscalStatus.Running:
Logger.DebugFormat("LeafInput: {0}, Piscal Running", leafInput.Id);
//leafInput.EndTime;
// continue running
break;
// it's exceeded the threshhold for being unresponsive but hasn't already been marked
if (IsLeafInputUnresponsive(leafInput) && !leafInput.IsUnresponsive)
{
var warning =
"Exceeded expected runtime, current elapsed time is "
+ $"{leafInput.TimeInProgress.ToReadableString()}";
PiscalWarningHandler($"LeafInput: {leafInput.Id}, {warning}", leafInput);
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Unresponsive, details: warning);
}
// continue running
break;
case PiscalStatus.Complete:
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Finishing, "Copying LeafOutput from Piscal");
@@ -252,5 +264,14 @@ namespace LeafWeb.WebCms.Services.PiscalQueue
}
}
}
private static bool IsLeafInputUnresponsive(ILeafInput leafInput)
{
// Test Unresponsive
//return true;
var piscalUnresponsiveHourCount = Convert.ToInt32(ConfigurationManager.AppSettings["PiscalUnresponsiveHourCount"]);
return leafInput.TimeInProgress > TimeSpan.FromHours(piscalUnresponsiveHourCount);
}
}
}