feat(dal, core, workloadBuilderWorker): Сервисы по работе с очередями (задачиами). Заготовка WorkloadBuilderWorker

This commit is contained in:
Mikhail Trubnikov
2026-04-21 16:54:39 +10:00
parent 2a6fd7177d
commit 001c09edaa
22 changed files with 762 additions and 4 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.WorkloadBuilderWorker-5cefb704-873b-40e7-b8a0-0537ca29e5ed</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,45 @@
using Elastic.CommonSchema.Serilog;
using PARR.Core;
using PARR.DAL;
using PARR.DAL.Services.Interfaces.Job;
using PARR.Infrastructure;
using PARR.WorkloadBuilderWorker;
using PARR.WorkloadBuilderWorker.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());
});
#region PARR modules
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);
#endregion
var workerSettings = new WorkerSettings();
builder.Configuration.GetSection(nameof(WorkerSettings)).Bind(workerSettings);
builder.Services.AddSingleton(workerSettings);
builder.Services.AddHostedService<Worker>();
var host = builder.Build();
host.Run();

View File

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

View File

@@ -0,0 +1,9 @@
using PARR.Domain.Settings;
namespace PARR.WorkloadBuilderWorker.Settings
{
public record WorkerSettings
{
public MqSettingsBase MqSettings { get; init; } = new();
}
}

View File

@@ -0,0 +1,29 @@
using PARR.Core.Services.Workload.Interfaces;
using PARR.WorkloadBuilderWorker.Settings;
namespace PARR.WorkloadBuilderWorker
{
public class Worker : BackgroundService
{
private readonly IWorkloadCacheBuilderService workloadCacheBuilderService;
private readonly WorkerSettings workerSettings;
public Worker(ILogger<Worker> logger, IWorkloadCacheBuilderService workloadCacheBuilderService, WorkerSettings WorkerSettings)
{
this.workloadCacheBuilderService = workloadCacheBuilderService;
this.workerSettings = WorkerSettings;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await workloadCacheBuilderService.ProcessMessagesAsync(workerSettings.MqSettings);
}
public override async Task StopAsync(CancellationToken cancellationToken)
{
await workloadCacheBuilderService.StopProcessingAsync();
await base.StopAsync(cancellationToken);
}
}
}

View File

@@ -0,0 +1,35 @@
{
"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": {
"HostName": "10.99.253.216"
}
}
}

View File

@@ -0,0 +1,33 @@
{
"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": {
"MqSettings": {
"HostName": "parr-rabbitmq",
"QueueName": "parr-task-workload",
"User": "task_workload_reader",
"Password": "sdjfgIYFdifyKJFDhvsad@!314d"
}
}
}