feat(aihitRelationshipsSyncer): Реализована логика синхронизации связей между Unit+CI/CD

This commit is contained in:
Mikhail Kuznetsov
2025-05-27 11:32:05 +10:00
parent cc52818d29
commit 078c8b540f
33 changed files with 4389 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM 10.99.253.167:8090/dotnet/runtime:7.0 AS base
WORKDIR /app
# This stage is used to build the service project
FROM 10.99.253.167:8090/dotnet/sdk:7.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["NuGet.config", "."]
COPY ["PARR.AIHITRelationshipsSyncerWorker/PARR.AIHITRelationshipsSyncerWorker.csproj", "PARR.AIHITRelationshipsSyncerWorker/"]
COPY ["PARR.AIHITRelationshipsSyncer/PARR.AIHITRelationshipsSyncer.csproj", "PARR.AIHITRelationshipsSyncer/"]
COPY ["PARR.BLL/PARR.BLL.csproj", "PARR.BLL/"]
COPY ["PARR.Common/PARR.Common.csproj", "PARR.Common/"]
COPY ["PARR.Constants/PARR.Constants.csproj", "PARR.Constants/"]
COPY ["PARR.DAL/PARR.DAL.csproj", "PARR.DAL/"]
RUN dotnet restore "./PARR.AIHITRelationshipsSyncerWorker/PARR.AIHITRelationshipsSyncerWorker.csproj"
COPY . .
WORKDIR "/src/PARR.AIHITRelationshipsSyncerWorker"
RUN dotnet build "./PARR.AIHITRelationshipsSyncerWorker.csproj" -c $BUILD_CONFIGURATION -o /app/build
# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
ARG app_version=0.0.0-default
RUN dotnet publish "./PARR.AIHITRelationshipsSyncerWorker.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:Version=$app_version
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PARR.AIHITRelationshipsSyncerWorker.dll"]

View File

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-PARR.AIHITRelationshipsSyncerWorker-529ba045-500b-4aca-9aad-871e85ded4d6</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.6.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1-Preview.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.AIHITRelationshipsSyncer\PARR.AIHITRelationshipsSyncer.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,31 @@
using Elastic.CommonSchema.Serilog;
using PARR.AIHITRelationshipsSyncer;
using PARR.AIHITRelationshipsSyncerWorker;
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());
});
builder.Services.InstallAihitRelationshpsSyncerServices(builder.Configuration);
builder.Configuration.AddAihitRelationshpsSyncerConfigurations(builder.Services);
builder.Services.AddAihitRelationshpsSyncerSettings(builder.Configuration);
builder.Services.AddHostedService<Worker>();
var host = builder.Build();
host.Run();

View File

@@ -0,0 +1,14 @@
{
"profiles": {
"PARR.AIHITRelationshipsSyncerWorker": {
"commandName": "Project",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true
},
"Container (Dockerfile)": {
"commandName": "Docker"
}
}
}

View File

@@ -0,0 +1,27 @@
using PARR.AIHITRelationshipsSyncer;
namespace PARR.AIHITRelationshipsSyncerWorker;
public class Worker : BackgroundService
{
private readonly IServiceProvider serviceProvider;
public Worker(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
using (var scope = serviceProvider.CreateScope())
{
var relationshipsSyncer = scope.ServiceProvider.GetService<IRelationshipsSyncer>();
if (relationshipsSyncer == null)
throw new Exception($"<22><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> {nameof(IRelationshipsSyncer)}");
await relationshipsSyncer.StartAsync();
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@@ -0,0 +1,15 @@
{
"ConnectionStrings": {
"AihitConnection": "Data Source=10.248.19.97; Initial Catalog=mao2;User ID=awhit-ipp-parr;pwd=ET3h$9y1LH#D;TrustServerCertificate=true;",
"DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"WorkerSettings": {
"RepeatEvery": "12:00:00"
}
}