Piscal Queue working more resilient to error

This commit is contained in:
2016-04-18 10:44:36 -04:00
parent 6623aa48ea
commit ca1a235c1d
21 changed files with 418 additions and 176 deletions
+57
View File
@@ -0,0 +1,57 @@
using System;
using Hangfire;
using LeafWeb.Core.DAL;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Remote;
using NLog;
namespace LeafWeb.Web.Services
{
public abstract class PiscalQueueBase : IDisposable
{
protected readonly DataService DataService;
protected readonly PiscalService PiscalService;
protected readonly Logger Logger;
protected PiscalQueueBase(DataService dataService, PiscalService piscalService)
{
DataService = dataService;
PiscalService = piscalService;
Logger = LogManager.GetLogger(GetType().Name);
}
protected PiscalQueueBase() : this(new DataService(), new PiscalService()) { }
protected string FormatException(Exception ex, int leafInputId)
{
return
$"LeafInput: {leafInputId}{Environment.NewLine}" +
$"Class: {GetType().Name}{Environment.NewLine}" +
$"Exception: {ex.Message}{Environment.NewLine}" +
(ex.InnerException != null ? $"InnerException: {ex.InnerException}{Environment.NewLine}" : string.Empty)
+ $"StackTrace: {ex.StackTrace}";
}
protected void PiscalExceptionNotify(PiscalClientException ex, LeafInput leafInput)
{
var errorMessage = FormatException(ex, ex.LeafInputId);
Logger.Error(errorMessage);
BackgroundJob.Enqueue<EmailNotificationService>(
email => email.SendAdministratorMessage($"LeafWeb: PiscalQueue {GetType().Name} Exception", errorMessage));
// TODO send user email too
if (leafInput != null)
{
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Exception, "Error occurred processing LeafInput",
ex.Message);
BackgroundJob.Enqueue<Cleanup>(s => s.DoWork(leafInput.Id));
}
}
public void Dispose()
{
DataService.Dispose();
}
}
}