feat(api, Core, TaskReconciliationWorker): Воркер обработки зависших задач. Доработка логики.

This commit is contained in:
Mikhail Trubnikov
2026-04-23 16:08:16 +10:00
parent 7da2265d1c
commit e8086b3a7d
13 changed files with 275 additions and 6 deletions

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-PARR.TaskReconciliationWorker-90386488-d496-4f4d-8dcd-7dcc50882876</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.6.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PARR.Core\PARR.Core.csproj" />
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
<ProjectReference Include="..\PARR.Domain\PARR.Domain.csproj" />
<ProjectReference Include="..\PARR.Infrastructure\PARR.Infrastructure.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,49 @@
using Elastic.CommonSchema.Serilog;
using PARR.Core;
using PARR.DAL;
using PARR.Infrastructure;
using PARR.TaskReconciliationWorker.Settings;
using Serilog;
var builder = Host.CreateApplicationBuilder();
builder.Services.AddLogging(config =>
{
config.ClearProviders();
var logger = new LoggerConfiguration();
if (builder.Environment.IsProduction())
logger.WriteTo.Console(new EcsTextFormatter());
else
logger.WriteTo.Console();
logger.ReadFrom.Configuration(builder.Configuration);
config.AddSerilog(logger.CreateLogger());
});
// --- Настройки ---
var workerSettings = new WorkerSettings();
builder.Configuration.GetSection(nameof(WorkerSettings)).Bind(workerSettings);
builder.Services.InstallDalServices(builder.Configuration);
builder.Services.AddCoreServices(builder.Configuration);
builder.Services.AddInfrastructureServices(builder.Configuration);
builder.Configuration.AddDalConfigurations(builder.Services);
builder.Services.AddDallSettings(builder.Configuration);
builder.Services.AddTaskManagement((provider, taskType) =>
{
// настройки очередей
//var workerSettings = provider.GetRequiredService<WorkerSettings>();
if (workerSettings.MqSettings.Tasks.TryGetValue(taskType, out var settings))
return settings;
throw new ArgumentException($"Настройки для типа задания {taskType} не найдены в конфигурации.");
});
builder.Services.AddTaskReconciliation(workerSettings);
var host = builder.Build();
host.Run();

View File

@@ -0,0 +1,11 @@
{
"profiles": {
"PARR.TaskReconciliationWorker": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,18 @@
using PARR.Domain.Enums;
using PARR.Domain.Settings;
namespace PARR.TaskReconciliationWorker.Settings
{
internal class WorkerSettings : IReconciliationSettings
{
public TimeSpan CheckInterval { get; set; } = TimeSpan.FromMinutes(10);
public int MaxTaskPerRun { get; set; } = 100;
public MqSettings MqSettings { get; set; } = new();
}
internal class MqSettings
{
public Dictionary<TaskTypeEnum, MqSettingsBase> Tasks { get; set; } = new();
}
}

View File

@@ -0,0 +1,38 @@
{
"ConnectionStrings": {
"RedisConnection": "10.99.253.216:6379,password=ParrP@ssPtk202MMdevDvs"
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "log/log-.txt",
"rollingInterval": "Day"
}
}
]
},
"WorkerSettings": {
"MqSettings": {
"Tasks": {
"Workload": {
"HostName": "10.99.253.216"
}
}
}
}
}

View File

@@ -0,0 +1,39 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;",
"RedisConnection": "parr-redis:6379,password=ParrP@ssPtk202MMdevDvs"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.EntityFrameworkCore": "Error",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning",
"Microsoft.AspNetCore": "Warning"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.EntityFrameworkCore": "Error",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
},
"WorkerSettings": {
"CheckInterval": "00:10:00",
"MaxTaskPerRun": 100,
"MqSettings": {
"Tasks": {
"Workload": {
"HostName": "parr-rabbitmq",
"QueueName": "parr-task-workload",
"User": "task_workload_writer",
"Password": "UFtsduifytIUR$^85382Wt1few"
}
}
}
}
}