New process type; refactor auto process

This commit is contained in:
Michał Zieliński
2024-03-25 10:43:05 +01:00
parent 0bc759605d
commit f85d14c31c
4 changed files with 358 additions and 185 deletions

View File

@@ -238,9 +238,9 @@ namespace WebAPI.Controllers
}
}
[HttpGet]
[Route("AutoProcess/{apiKey}/{type}")]
[Route("AutoProcess/{apiKey}")]
[AllowAnonymous]
public IActionResult AutoProcess(string apiKey, string type)
public IActionResult AutoProcess(string apiKey)
{
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
{
@@ -251,62 +251,80 @@ namespace WebAPI.Controllers
throw new Exception("Google Sheets API not initialized");
}
try
{
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.Records!.Any(x => x.Code == "ProcessType" && x.Desc1 == type)
)
.OrderBy(x => x.CreatedAt)
.ToList();
string[] processTypes = new string[] {
"T3-SingleSource",
"T3-MultiSourceSummary",
"T3-SourceYearSummary",
"T3-MultiSourceYearSummary",
"T3-MultiSourceCopySelectedCodes",
"T3-MultiSourceCopySelectedCodesYearSummary"
};
if (processWorkerLayers.Count() == 0)
foreach (string type in processTypes)
{
try
{
logsController.AddEntry(new LogEntry
{
Title = "No Layers to process.",
Title = $"Processing: {type}",
Type = LogEntryType.info,
LogType = LogType.process,
CreatedAt = DateTime.UtcNow,
});
return Ok();
}
foreach (Layer processWorker in processWorkerLayers)
{
try
{
ProcessLayer(processWorker);
}
catch (Exception e)
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.Records!.Any(x => x.Code == "ProcessType" && x.Desc1 == type)
)
.OrderBy(x => x.CreatedAt)
.ToList();
if (processWorkerLayers.Count() == 0)
{
logsController.AddEntry(new LogEntry
{
Title = $"{processWorker!.Name}, {processWorker.Id}",
Type = LogEntryType.error,
Title = "No Layers to process.",
Type = LogEntryType.info,
LogType = LogType.process,
Message = e.ToString(),
CreatedAt = DateTime.UtcNow
CreatedAt = DateTime.UtcNow,
});
}
foreach (Layer processWorker in processWorkerLayers)
{
try
{
ProcessLayer(processWorker);
}
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();
}
catch (Exception e)
{
logsController.AddEntry(new LogEntry
catch (Exception e)
{
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.process,
Message = e.ToString(),
CreatedAt = DateTime.UtcNow
});
return BadRequest(e.ToString());
logsController.AddEntry(new LogEntry
{
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.process,
Message = e.ToString(),
CreatedAt = DateTime.UtcNow
});
}
}
return Ok();
}
internal void ProcessLayer(Layer processWorker)
{
@@ -356,6 +374,21 @@ namespace WebAPI.Controllers
});
return;
}
if (processType == "T3-MultiSourceCopySelectedCodesYearSummary")
{
T3MultiSourceCopySelectedCodesYearSummaryProcessor processor = new T3MultiSourceCopySelectedCodesYearSummaryProcessor(db, googleSheetValues, this);
processor.process(processWorker!);
logsController.AddEntry(new LogEntry
{
Title = $"{processWorker!.Name}, {processWorker.Id}",
Type = LogEntryType.info,
LogType = LogType.process,
Message = "Success",
CreatedAt = DateTime.UtcNow
});
return;
}
string? month = processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
if (month == null)
{
@@ -379,7 +412,6 @@ namespace WebAPI.Controllers
{
T3MultiSourceCopySelectedCodesProcessor processor = new T3MultiSourceCopySelectedCodesProcessor(db, googleSheetValues, this);
processor.process(processWorker!);
processor.updateReport();
break;
}
}