This commit is contained in:
82
server/AyaNova/generator/CoreJobNotify.cs
Normal file
82
server/AyaNova/generator/CoreJobNotify.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Notification processor
|
||||
///
|
||||
/// </summary>
|
||||
internal static class CoreJobNotify
|
||||
{
|
||||
private static bool NotifyIsRunning = false;
|
||||
private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("CoreJobNotify");
|
||||
private static DateTime lastRun = DateTime.MinValue;
|
||||
private static TimeSpan DELETE_AFTER_AGE = new TimeSpan(90, 0, 0, 0);
|
||||
private static TimeSpan RUN_EVERY_INTERVAL = new TimeSpan(0, 2, 0);//once every 2 minutes minimum
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// DoSweep
|
||||
//
|
||||
public static async Task DoWorkAsync()
|
||||
{
|
||||
log.LogTrace("Checking if Notify should run");
|
||||
if (NotifyIsRunning)
|
||||
{
|
||||
log.LogTrace("Notify is running already exiting this cycle");
|
||||
return;
|
||||
}
|
||||
//This will get triggered roughly every minute, but we don't want to deliver that frequently
|
||||
if (DateTime.UtcNow - lastRun < RUN_EVERY_INTERVAL)
|
||||
{
|
||||
log.LogTrace($"Notify ran less than {RUN_EVERY_INTERVAL}, exiting this cycle");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
NotifyIsRunning = true;
|
||||
log.LogTrace("Notify set to RUNNING state and starting now");
|
||||
|
||||
|
||||
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
|
||||
{
|
||||
//select all jobs with no deliver date or deliver date no longer in future
|
||||
//Open question: what to do with failed deliveries?
|
||||
//we dont' want them piling up but we don't want to just dump them do we?
|
||||
//it should be only mail ones that fail, not app ones, there's no way for an app delivery to fail as it's just put in a table
|
||||
//### PLAN if it's an smtp delivery that fails and it's to someone who can be delivered in app then it should send an inapp notification of
|
||||
//delivery failure and still delete the smtp delivery
|
||||
//If it's not possible to notify the person via in app of the failed smtp then perhaps it notifies OPS personnel and biz admin personnel
|
||||
//NEW NOTIFICATION SUBSCRIPTION EVENT TYPE:
|
||||
//OPERATIONS_PROBLEMS - backup, notifications, out of memory, what have you, anyone can subscribe to it regardless of rights
|
||||
//this is just to let people know there is a problem
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
log.LogTrace("Notify is done setting to not running state and tagging lastRun timestamp");
|
||||
lastRun = DateTime.UtcNow;
|
||||
NotifyIsRunning = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
}//eoc
|
||||
|
||||
|
||||
}//eons
|
||||
|
||||
Reference in New Issue
Block a user