LibAICORE 1.1.4-alpha-gf81b1bf205
A corejob is a task that is:
- asynchronous, may take seconds, minutes, or hours
- transient, variables not in db/files/etc are deleted on finish
- non-importing, files may be GB or TB so files are edited one row at a time (do not import everything into RAM!!)
- authenticated, users must be checked for permissions before every action - this is done with keycloak (auth.aicore.ca)
- private, users should have absolutely no access to any information (files, DB, corejobs) from other companies (customers) - any files outside of /AICORE/Customers/[company] should be inaccessible
- developer maintained, a developer at coredata is expected to modify corejobs according to logic requirements
Victor wanted the last point to be temporary, so customers can eventually be trained to modify corejobs in a low-code environment (AICORE), but this low-code environment of only JSON files was resulting in the least readable code I've ever seen (/AICORE/Customers/Normandeau/Customers/QuoteToInvoice) and this system was completely unreasonable to train a non-technical customer on, while the system took an absurd amount of extra time for coredata developers to test and develop (no if statements or loops, every new command/instruction meant making a new API even if it was only for one customer, the standard IDE was notepad++ with no schema - I would compare the experience to writing x86 assembly code in a raw text editor with no branch/jump instruction) - so I just hacked together a quick replacement for ImecCoreFMS functions that needed to be finished quickly
Logs are async, since every single log message info-level or higher may be sent to the customer via SSE
This library was made for ASP.NET Core 7 using reflection and dependency injection - please read up on both if you want to edit the library
To call corejobs made with the AICORE low-code JSON system, a function ExecuteCMD has been provided
Full example:
public class TestController : ControllerBase
{
private readonly CorejobRegistry _corejobs;
public TestController(CorejobRegistry corejobs)
{
_corejobs = corejobs;
}
[HttpPost]
[Route("test_registry")]
public async Task Test()
{
await _corejobs.RunCorejobSSE("test_registry", null);
}
}
public class CorejobRegistryTest : CorejobRegistryBase
{
// Has access to all services a controller does:
private readonly ExampleDBContext _db;
public CorejobRegistryTest(IHttpContextAccessor httpContextAccessor, ILogger<CorejobRegistryTest> logger, IConfiguration configuration, ExampleDBContext db) : base(httpContextAccessor, logger, configuration)
{
_db = db;
}
[Corejob("test_registry")]
[Customer("coredata")]
public async Task<Result> TestRegistry()
{
string? username = GetUserName();
var user = await _db.Users.Where(u => u.username == username).FirstOrDefaultAsync();
string customer_folder = await GetCustomerRoot();
await LogInformation("Current user: " + username + " (" + user.email + ") Customer folder: " + customer_folder);
// Low-code JSON corejob
await ExecuteCMD("bf9fb9b6-8c42-495f-a6e6-2da9ed4a8909", new() {
["date"] = DateTime.Now.ToString()
});
string? customer = GetCustomerName();
return Result.Ok().WithSuccess("Successfully ran test_registry for customer " + customer);
// Any exceptions will automatically be caught and replaced with a Result.Fail() with the exception message; no try/catch needed
}
}
Remember to add this line in Program.cs:
builder.Services.AddCorejobs();
No packages depend on LibAICORE.
.NET 7.0
- FluentResults (>= 3.15.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- RestSharp (>= 110.2.0)
- System.IdentityModel.Tokens.Jwt (>= 7.3.1)