AutoProcess Refactor. Logging improvement. MultiSourceSummaryProcessor

This commit is contained in:
Michał Zieliński
2023-11-06 22:52:07 +01:00
parent e7c413d9cf
commit 8c26698dc8
4 changed files with 297 additions and 106 deletions

View File

@@ -186,20 +186,143 @@ namespace WebAPI.Controllers
return Unauthorized();
}
List<Layer> processWorkerLayers;
List<Layer> layersToProcess;
try
{
processWorkerLayers = db.Layers
List<Layer> processWorkerLayers = db.Layers
.Include(x => x.Records)
.Where(x =>
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ProcessWorker") &&
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True")
//&& x.Number == 215
//&& x.Number == 262
)
.OrderBy(x => x.CreatedAt)
.ToList();
layersToProcess = new List<Layer>();
if (processWorkerLayers.Count() == 0)
{
logsController.AddEntry(new LogEntry
{
Title = "No Layers to process.",
Type = LogEntryType.info,
LogType = LogType.process,
CreatedAt = DateTime.UtcNow,
});
return Ok();
}
foreach (Layer processWorker in processWorkerLayers)
{
try
{
string name = processWorker.Name;
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
if (year == null)
{
throw new Exception("Year record nod found");
}
if (int.Parse(year!) < DateTime.UtcNow.Year)
{
logsController.AddEntry(new LogEntry
{
Title = $"{processWorker!.Name}, {processWorker.Id}",
Type = LogEntryType.warning,
LogType = LogType.process,
Message = "processLayer is out of date. Should be disabled. Not processed.",
CreatedAt = DateTime.UtcNow
});
continue;
}
string? processType = processWorker?.Records?.SingleOrDefault(x => x.Code == "ProcessType")?.Desc1;
if (processType == null)
{
throw new Exception("ProcessType record not found");
}
if (processType == "T3-SourceYearSummary")
{
if (int.Parse(year!) < DateTime.UtcNow.Year)
{
logsController.AddEntry(new LogEntry
{
Title = $"{processWorker!.Name}, {processWorker.Id}",
Type = LogEntryType.warning,
LogType = LogType.process,
Message = "processLayer is out of date. Should be disabled. Not processed",
CreatedAt = DateTime.UtcNow
});
continue;
}
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this, logsController);
processor.process(processWorker!);
logsController.AddEntry(new LogEntry
{
Title = $"{processWorker!.Name}, {processWorker.Id}",
Type = LogEntryType.info,
LogType = LogType.process,
Message = "Success",
CreatedAt = DateTime.UtcNow
});
continue;
}
string? month = processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
if (month == null)
{
throw new Exception("Month record not found");
}
if (int.Parse(month!) < DateTime.UtcNow.Month)
{
logsController.AddEntry(new LogEntry
{
Title = $"{processWorker!.Name}, {processWorker.Id}",
Type = LogEntryType.warning,
LogType = LogType.process,
Message = "processLayer is out of date. Should be disabled.",
CreatedAt = DateTime.UtcNow
});
}
switch (processType!)
{
case "T3-SingleSource":
{
T3SingleSourceProcessor processor = new T3SingleSourceProcessor(db, googleSheetValues, this);
processor.process(processWorker!);
break;
}
case "T3-MultiSourceSummary":
{
T3MultiSourceSummaryProcessor processor = new T3MultiSourceSummaryProcessor(db, googleSheetValues, this);
processor.process(processWorker!);
break;
}
}
logsController.AddEntry(new LogEntry
{
Title = $"{processWorker!.Name}, {processWorker.Id}",
Type = LogEntryType.info,
LogType = LogType.process,
Message = "Success",
CreatedAt = DateTime.UtcNow
});
} catch (Exception e)
{
logsController.AddEntry(new LogEntry
{
Title = $"{processWorker!.Name}, {processWorker.Id}",
Type = LogEntryType.error,
LogType = LogType.process,
Message = e.ToString(),
CreatedAt = DateTime.UtcNow
});
}
}
return Ok();
foreach (Layer processWorker in processWorkerLayers)
{
@@ -216,8 +339,8 @@ namespace WebAPI.Controllers
});
return BadRequest();
}
string? sourceName = processWorker?.Records?.Single(x => x.Code == "Source")?.Desc1;
if (sourceName == null)
List<Record>? sources = processWorker?.Records?.Where(x => x.Code == "Source").ToList();
if (sources != null && sources.Count() == 0)
{
logsController.AddEntry(new LogEntry
{
@@ -234,15 +357,17 @@ namespace WebAPI.Controllers
{
if (processWorker != null)
{
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
processor.process(processWorker);
//T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
// processor.process(processWorker);
}
}
else
} else if (processType == "T3-MultiSourceSummary")
{
var tst = 5;
} else
{
Layer sourceLayer = db.Layers.Include(x => x.Records)
.Single(x => x.Name == sourceName);
.Single(x => x.Name == sources!.First().Desc1);
if (sourceLayer == null)
{
logsController.AddEntry(new LogEntry
@@ -262,21 +387,7 @@ namespace WebAPI.Controllers
var endDateParsed = DateTime.ParseExact(endDate, "yyyy.MM.dd", null);
if (startDateParsed.Date <= DateTime.UtcNow.Date && endDateParsed.Date >= DateTime.UtcNow.Date)
{
switch (processType)
{
case "Copy":
CopyProcessor cp = new CopyProcessor(db, googleSheetValues, this);
cp.process(sourceLayer, processWorker?.Id);
break;
case "Deaggregation":
DeaggregationProcessor dp = new DeaggregationProcessor(db, googleSheetValues, this);
dp.process(sourceLayer, processWorker?.Id);
break;
case "T3-SingleSource":
T3SingleSourceProcessor processor = new T3SingleSourceProcessor(db, googleSheetValues, this);
processor.process(sourceLayer, processWorker?.Id);
break;
}
logsController.AddEntry(new LogEntry
{
Title = $"Process Success, {sourceLayer.Name}",