This commit is contained in:
@@ -156,6 +156,22 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
#region PROCESSOR
|
#region PROCESSOR
|
||||||
|
|
||||||
|
internal static bool KeepOnWorking()
|
||||||
|
{
|
||||||
|
ApiServerState serverState = ServiceProviderProvider.ServerState;
|
||||||
|
|
||||||
|
//system lock (no license) is a complete deal breaker for continuation beyond here
|
||||||
|
if (serverState.IsSystemLocked) return false;
|
||||||
|
|
||||||
|
if (serverState.IsMigrateMode)
|
||||||
|
{
|
||||||
|
log.LogDebug("Server is in migrate mode, skipping processing jobs");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool ActivelyProcessing = false;
|
static bool ActivelyProcessing = false;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Process all jobs (stock jobs and those found in operations table)
|
/// Process all jobs (stock jobs and those found in operations table)
|
||||||
@@ -169,6 +185,7 @@ namespace AyaNova.Biz
|
|||||||
log.LogTrace("ProcessJobs called but actively processing other jobs so returning");
|
log.LogTrace("ProcessJobs called but actively processing other jobs so returning");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
ActivelyProcessing = true;
|
ActivelyProcessing = true;
|
||||||
log.LogDebug("Processing internal jobs");
|
log.LogDebug("Processing internal jobs");
|
||||||
try
|
try
|
||||||
@@ -184,39 +201,38 @@ namespace AyaNova.Biz
|
|||||||
//### Server state dependent jobs
|
//### Server state dependent jobs
|
||||||
ApiServerState serverState = ServiceProviderProvider.ServerState;
|
ApiServerState serverState = ServiceProviderProvider.ServerState;
|
||||||
|
|
||||||
//system lock (no license) is a complete deal breaker for continuation beyond here
|
if (!KeepOnWorking()) return;
|
||||||
if (serverState.IsSystemLocked) return;
|
|
||||||
|
|
||||||
if (serverState.IsMigrateMode){
|
|
||||||
log.LogDebug("Server is in migrate mode, skipping non-critical internal jobs");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.LogTrace("Processing level 2 internal jobs");
|
log.LogTrace("Processing level 2 internal jobs");
|
||||||
|
|
||||||
// #if (DEBUG)
|
// #if (DEBUG)
|
||||||
// log.LogInformation("Processing semi-critical internal jobs (backup, pm, notification etc)");
|
// log.LogInformation("Processing semi-critical internal jobs (backup, pm, notification etc)");
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
//BACKUP
|
//BACKUP
|
||||||
await CoreJobBackup.DoWorkAsync();
|
await CoreJobBackup.DoWorkAsync();
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
//NOTIFICATIONS
|
//NOTIFICATIONS
|
||||||
await CoreJobNotify.DoWorkAsync();
|
await CoreJobNotify.DoWorkAsync();
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
await CoreNotificationSweeper.DoWorkAsync();
|
await CoreNotificationSweeper.DoWorkAsync();
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
|
|
||||||
//PM GENERATION
|
//PM GENERATION
|
||||||
await CoreJobPMGenerate.DoWorkAsync();
|
await CoreJobPMGenerate.DoWorkAsync();
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
|
|
||||||
//PM INVENTORY CHECK
|
//PM INVENTORY CHECK
|
||||||
if (AyaNova.Util.ServerGlobalBizSettings.Cache.UseInventory)
|
if (AyaNova.Util.ServerGlobalBizSettings.Cache.UseInventory)
|
||||||
await CoreJobPMInventoryCheck.DoWorkAsync();
|
await CoreJobPMInventoryCheck.DoWorkAsync();
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
|
|
||||||
//JOB SWEEPER / AND USER COUNT CHECK
|
//JOB SWEEPER / AND USER COUNT CHECK
|
||||||
await CoreJobSweeper.DoWorkAsync();
|
await CoreJobSweeper.DoWorkAsync();
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
|
|
||||||
//Clean temp folder
|
//Clean temp folder
|
||||||
CoreJobTempFolderCleanup.DoWork();
|
CoreJobTempFolderCleanup.DoWork();
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
|
|
||||||
log.LogTrace("Processing exclusive dynamic jobs");
|
log.LogTrace("Processing exclusive dynamic jobs");
|
||||||
|
|
||||||
@@ -226,6 +242,7 @@ namespace AyaNova.Biz
|
|||||||
List<OpsJob> exclusiveJobs = await GetReadyJobsExclusiveOnlyAsync();
|
List<OpsJob> exclusiveJobs = await GetReadyJobsExclusiveOnlyAsync();
|
||||||
foreach (OpsJob j in exclusiveJobs)
|
foreach (OpsJob j in exclusiveJobs)
|
||||||
{
|
{
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ProcessJobAsync(j);
|
await ProcessJobAsync(j);
|
||||||
@@ -250,11 +267,12 @@ namespace AyaNova.Biz
|
|||||||
//NON-EXCLUSIVE JOBS
|
//NON-EXCLUSIVE JOBS
|
||||||
//
|
//
|
||||||
log.LogTrace("Processing non-exclusive dynamic jobs");
|
log.LogTrace("Processing non-exclusive dynamic jobs");
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
//These fire and forget but use a technique to bubble up exceptions anyway
|
//These fire and forget but use a technique to bubble up exceptions anyway
|
||||||
List<OpsJob> sharedJobs = await GetReadyJobsNotExlusiveOnlyAsync();
|
List<OpsJob> sharedJobs = await GetReadyJobsNotExlusiveOnlyAsync();
|
||||||
foreach (OpsJob j in sharedJobs)
|
foreach (OpsJob j in sharedJobs)
|
||||||
{
|
{
|
||||||
|
if (!KeepOnWorking()) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//System.Diagnostics.Debug.WriteLine($"JobsBiz processing NON-exclusive biz job {j.Name}");
|
//System.Diagnostics.Debug.WriteLine($"JobsBiz processing NON-exclusive biz job {j.Name}");
|
||||||
|
|||||||
@@ -4700,6 +4700,22 @@ namespace AyaNova.Biz
|
|||||||
public decimal QuantityRequired { get; set; }
|
public decimal QuantityRequired { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool KeepOnWorking(ILogger log)
|
||||||
|
{
|
||||||
|
ApiServerState serverState = ServiceProviderProvider.ServerState;
|
||||||
|
|
||||||
|
//system lock (no license) is a complete deal breaker for continuation beyond here
|
||||||
|
if (serverState.IsSystemLocked) return false;
|
||||||
|
|
||||||
|
if (serverState.IsMigrateMode)
|
||||||
|
{
|
||||||
|
log.LogInformation("Server is in migrate mode, skipping processing further PM's");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Process generation of pms to workorders
|
// Process generation of pms to workorders
|
||||||
//
|
//
|
||||||
@@ -4721,6 +4737,11 @@ namespace AyaNova.Biz
|
|||||||
//process those pms
|
//process those pms
|
||||||
foreach (long pmid in l)
|
foreach (long pmid in l)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(!KeepOnWorking(log)) return;
|
||||||
|
|
||||||
|
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
log.LogInformation($"processing pm id {pmid}");
|
log.LogInformation($"processing pm id {pmid}");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//CREATE (internal version)
|
//CREATE (internal version only called from within a transaction)
|
||||||
//
|
//
|
||||||
internal async Task<PartInventory> CreateAsync(dtInternalPartInventory newDtObject)
|
internal async Task<PartInventory> CreateAsync(dtInternalPartInventory newDtObject)
|
||||||
{
|
{
|
||||||
@@ -90,7 +90,7 @@ namespace AyaNova.Biz
|
|||||||
var LastEntry = await ct.PartInventory.OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == newDtObject.PartId && m.PartWarehouseId == newDtObject.PartWarehouseId);
|
var LastEntry = await ct.PartInventory.OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == newDtObject.PartId && m.PartWarehouseId == newDtObject.PartWarehouseId);
|
||||||
PartInventory newObject = new PartInventory();
|
PartInventory newObject = new PartInventory();
|
||||||
newObject.Description = newDtObject.Description;
|
newObject.Description = newDtObject.Description;
|
||||||
newObject.EntryDate = DateTime.UtcNow;
|
|
||||||
newObject.PartId = newDtObject.PartId;
|
newObject.PartId = newDtObject.PartId;
|
||||||
newObject.PartWarehouseId = newDtObject.PartWarehouseId;
|
newObject.PartWarehouseId = newDtObject.PartWarehouseId;
|
||||||
newObject.SourceId = newDtObject.SourceId;
|
newObject.SourceId = newDtObject.SourceId;
|
||||||
@@ -107,7 +107,7 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
newObject.Balance = newObject.Quantity;
|
newObject.Balance = newObject.Quantity;
|
||||||
}
|
}
|
||||||
|
newObject.EntryDate = DateTime.UtcNow;//validate is saying this is older than lastentrydate in a huge test migration on a crappy vm which is weird so moved here to last millisecond before validation
|
||||||
await ValidateAsync(newObject);
|
await ValidateAsync(newObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return null;
|
return null;
|
||||||
@@ -229,10 +229,10 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//date is newer than last entry date?
|
//Last entry date is newer than current entry date?
|
||||||
if (proposedObj.LastEntryDate != null && proposedObj.LastEntryDate > proposedObj.EntryDate)
|
if (proposedObj.LastEntryDate != null && proposedObj.LastEntryDate > proposedObj.EntryDate)
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "generalerror", "LastEntryDate is newer than EntryDate");
|
AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "generalerror", $"LastEntryDate ({proposedObj.LastEntryDate.ToString()}) is newer than EntryDate ({proposedObj.EntryDate.ToString()})");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3691,7 +3691,10 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
await PartValidateAsync(newObject, null);
|
await PartValidateAsync(newObject, null);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
|
{
|
||||||
|
await transaction.RollbackAsync();
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await PartBizActionsAsync(AyaEvent.Created, newObject, null);
|
await PartBizActionsAsync(AyaEvent.Created, newObject, null);
|
||||||
@@ -4029,13 +4032,13 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (pib.HasErrors)
|
if (pib.HasErrors)
|
||||||
{
|
{
|
||||||
foreach (var e in pib.Errors)
|
if (pib.Errors.Count == 1 && pib.Errors[0].Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
|
||||||
{
|
{
|
||||||
if (e.Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
|
AddError(pib.Errors[0].Code, "Quantity", pib.Errors[0].Message);
|
||||||
AddError(e.Code, "Quantity", e.Message);
|
return;
|
||||||
else
|
|
||||||
AddError(e.Code, e.Target, e.Message);
|
|
||||||
}
|
}
|
||||||
|
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({pi.Description}):{pib.GetErrorsAsString()}");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4101,10 +4104,8 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (pib.HasErrors)
|
if (pib.HasErrors)
|
||||||
{
|
{
|
||||||
foreach (var e in pib.Errors)
|
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({pi.Description}):{pib.GetErrorsAsString()}");
|
||||||
{
|
return;
|
||||||
AddError(e.Code, e.Target, e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4118,6 +4119,7 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//MAIN ROUTE DURING MIGRATE
|
||||||
//CONSUME INVENTORY
|
//CONSUME INVENTORY
|
||||||
dtInternalPartInventory pi =
|
dtInternalPartInventory pi =
|
||||||
new dtInternalPartInventory
|
new dtInternalPartInventory
|
||||||
@@ -4133,13 +4135,13 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (pib.HasErrors)
|
if (pib.HasErrors)
|
||||||
{
|
{
|
||||||
foreach (var e in pib.Errors)
|
if (pib.Errors.Count == 1 && pib.Errors[0].Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
|
||||||
{
|
{
|
||||||
if (e.Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
|
AddError(pib.Errors[0].Code, "Quantity", pib.Errors[0].Message);
|
||||||
AddError(e.Code, "Quantity", e.Message);
|
return;
|
||||||
else
|
|
||||||
AddError(e.Code, e.Target, e.Message);
|
|
||||||
}
|
}
|
||||||
|
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({pi.Description}):{pib.GetErrorsAsString()}");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4179,13 +4181,13 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (pib.HasErrors)
|
if (pib.HasErrors)
|
||||||
{
|
{
|
||||||
foreach (var e in pib.Errors)
|
if (pib.Errors.Count == 1 && pib.Errors[0].Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
|
||||||
{
|
{
|
||||||
if (e.Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
|
AddError(pib.Errors[0].Code, "Quantity", pib.Errors[0].Message);
|
||||||
AddError(e.Code, "Quantity", e.Message);
|
return;
|
||||||
else
|
|
||||||
AddError(e.Code, e.Target, e.Message);
|
|
||||||
}
|
}
|
||||||
|
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({pi.Description}):{pib.GetErrorsAsString()}");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4241,10 +4243,8 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (pib.HasErrors)
|
if (pib.HasErrors)
|
||||||
{
|
{
|
||||||
foreach (var e in pib.Errors)
|
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({pi.Description}):{pib.GetErrorsAsString()}");
|
||||||
{
|
return;
|
||||||
AddError(e.Code, e.Target, e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4271,8 +4271,18 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
if (await pib.CreateAsync(piNew) == null)
|
if (await pib.CreateAsync(piNew) == null)
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piNew.Description}):{pib.GetErrorsAsString()}");
|
// AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piNew.Description}):{pib.GetErrorsAsString()}");
|
||||||
return;
|
// return;
|
||||||
|
if (pib.HasErrors)
|
||||||
|
{
|
||||||
|
if (pib.Errors.Count == 1 && pib.Errors[0].Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
|
||||||
|
{
|
||||||
|
AddError(pib.Errors[0].Code, "Quantity", pib.Errors[0].Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piNew.Description}):{pib.GetErrorsAsString()}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ //Consume serial numbers from part
|
{ //Consume serial numbers from part
|
||||||
@@ -5851,7 +5861,7 @@ namespace AyaNova.Biz
|
|||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
o.UnitViz = unitInfo.Serial;
|
o.UnitViz = unitInfo.Serial;
|
||||||
o.UnitDescriptionViz = unitInfo.Description;
|
o.UnitDescriptionViz = unitInfo.Description;
|
||||||
o.UnitMeteredViz=unitInfo.Metered;
|
o.UnitMeteredViz = unitInfo.Metered;
|
||||||
if (populateForReporting)
|
if (populateForReporting)
|
||||||
{
|
{
|
||||||
o.AddressViz = unitInfo.Address;
|
o.AddressViz = unitInfo.Address;
|
||||||
|
|||||||
Reference in New Issue
Block a user