This commit is contained in:
@@ -209,6 +209,9 @@ namespace AyaNova.Biz
|
|||||||
//PM GENERATION
|
//PM GENERATION
|
||||||
await CoreJobPMGenerate.DoWorkAsync();
|
await CoreJobPMGenerate.DoWorkAsync();
|
||||||
|
|
||||||
|
//PM INVENTORY CHECK
|
||||||
|
await CoreJobPMInventoryCheck.DoWorkAsync();
|
||||||
|
|
||||||
//JOB SWEEPER / AND USER COUNT CHECK
|
//JOB SWEEPER / AND USER COUNT CHECK
|
||||||
await CoreJobSweeper.DoWorkAsync();
|
await CoreJobSweeper.DoWorkAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -4746,7 +4746,14 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region GENERATION
|
|
||||||
|
#region GENERATION
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Process generation of pms to workorders
|
||||||
|
//
|
||||||
|
internal static async Task ProcessInsufficientInventoryNotificationAsync(AyContext ct, ILogger log)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Process generation of pms to workorders
|
// Process generation of pms to workorders
|
||||||
|
|||||||
81
server/AyaNova/generator/CoreJobPMInventoryCheck.cs
Normal file
81
server/AyaNova/generator/CoreJobPMInventoryCheck.cs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using AyaNova.Models;
|
||||||
|
using AyaNova.Util;
|
||||||
|
|
||||||
|
namespace AyaNova.Biz
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Preventive maintenance generator
|
||||||
|
/// turn PMs into Work orders
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
internal static class CoreJobPMInventoryCheck
|
||||||
|
{
|
||||||
|
private static bool IsRunning = false;
|
||||||
|
private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("CoreJobPMInventoryCheck");
|
||||||
|
private static DateTime lastRun = DateTime.MinValue;
|
||||||
|
|
||||||
|
|
||||||
|
#if (DEBUG)
|
||||||
|
private static TimeSpan RUN_EVERY_INTERVAL = new TimeSpan(0, 0, 20);//no more frequently than once every 20 seconds
|
||||||
|
#else
|
||||||
|
private static TimeSpan RUN_EVERY_INTERVAL = new TimeSpan(0, 30, 0);//no more frequently than once every half hour
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
public static async Task DoWorkAsync()
|
||||||
|
{
|
||||||
|
log.LogTrace("Checking if CoreJobPMInventoryCheck should run");
|
||||||
|
if (IsRunning)
|
||||||
|
{
|
||||||
|
log.LogTrace("CoreJobPMInventoryCheck 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($"CoreJobPMInventoryCheck ran less than {RUN_EVERY_INTERVAL} ago, exiting this cycle");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//CHECK INVENTORY AND NOTIFY
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsRunning = true;
|
||||||
|
log.LogTrace("CoreJobPMInventoryCheck set to RUNNING state and starting now");
|
||||||
|
|
||||||
|
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
|
||||||
|
{
|
||||||
|
await PMBiz.ProcessInsufficientInventoryNotificationAsync(ct, log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
log.LogError(ex, $"Error processing CoreJobPMInventoryCheck ");
|
||||||
|
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.PMGenerationFailed, "PM Inventory check failure", "Preventive Maintenance", ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
log.LogTrace("CoreJobPMInventoryCheck has completed; setting to not running state and tagging lastRun timestamp");
|
||||||
|
lastRun = DateTime.UtcNow;
|
||||||
|
IsRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}//eoc
|
||||||
|
|
||||||
|
|
||||||
|
}//eons
|
||||||
|
|
||||||
Reference in New Issue
Block a user