Add run time to queue

This commit is contained in:
2017-01-27 14:07:36 -05:00
parent 4338b4fee5
commit 0711ae0ac8
24 changed files with 198 additions and 209 deletions
@@ -3,17 +3,18 @@ using System.Linq;
using System.Threading;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Remote;
using LeafWeb.WebCms.App_Start;
namespace LeafWeb.WebCms.Services.PiscalQueue
{
public class PiscalQueueManager : PiscalQueueBase
{
private static readonly object ProcessQueueLock = new object();
private static readonly object Lock = new object();
public void ProcessQueue()
{
// prevent multiple entry into processing the queue
if (Monitor.TryEnter(ProcessQueueLock))
if (Monitor.TryEnter(Lock))
{
Logger.DebugFormat("ProcessQueue entered");
@@ -31,7 +32,7 @@ namespace LeafWeb.WebCms.Services.PiscalQueue
{
Logger.DebugFormat("ProcessQueue exit");
Monitor.Exit(ProcessQueueLock);
Monitor.Exit(Lock);
}
}
else
@@ -40,6 +41,46 @@ namespace LeafWeb.WebCms.Services.PiscalQueue
}
}
public bool CancelPending(int leafInputId)
{
if (Monitor.TryEnter(Lock, TimeSpan.FromSeconds(1)))
{
Logger.DebugFormat("CancelLeafInput entered");
try
{
var leafInput = DataService.GetLeafInput(leafInputId);
if (!leafInput.IsCancellable)
return false;
if (leafInput.IsPending)
{
Logger.DebugFormat("LeafInput: {0}, Set Cancelled from Pending", leafInput.Id);
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Cancelled,
"Emailing cancellation notification to user",
$"Email: \'{leafInput.Email}\'");
// send notification immediately
BackgroundJobEnqueueRetry<EmailNotificationService>(email => email.SendLeafWebCancelled(leafInput.Id));
}
else if (leafInput.IsRunning)
{
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.CancelPending);
HangfireStartup.TriggerPiscalProcessQueue();
}
return true;
}
finally
{
Logger.DebugFormat("CancelLeafInput exit");
Monitor.Exit(Lock);
}
}
Logger.DebugFormat("CancelLeafInput locked");
return false;
}
private void StartCancelPending()
{
var cancelPendingLeafInputs =