feat(templateTaskGenerator): Написан TemplateTaskGenerator, читает очередь Mq parr-template-task-generator при получении id регламентной работы проверяет несозданные шаблоны. При наличии таковых пишет сообщение в очередь parr-template-generator
This commit is contained in:
@@ -35,7 +35,7 @@ namespace PARR.AIHITMainSyncer.Services
|
|||||||
|
|
||||||
public async Task SyncAsync(string msg)
|
public async Task SyncAsync(string msg)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Запуск синхронизации данных из очереди сообщений в ПАРР.");
|
//logger.LogInformation("Запуск синхронизации данных из очереди сообщений в ПАРР.");
|
||||||
var objFromQuery = transformService.GetModelFromJson<AihitMainDataMq>(msg);
|
var objFromQuery = transformService.GetModelFromJson<AihitMainDataMq>(msg);
|
||||||
if (objFromQuery == null)
|
if (objFromQuery == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
12
PARR.API.sln
12
PARR.API.sln
@@ -92,6 +92,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.AIHITRelationshipsSync
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.TemplateGeneratorWorker", "PARR.TemplateGeneratorWorker\PARR.TemplateGeneratorWorker.csproj", "{17245D0B-3290-4C96-B5B1-4B0711BABAF2}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.TemplateGeneratorWorker", "PARR.TemplateGeneratorWorker\PARR.TemplateGeneratorWorker.csproj", "{17245D0B-3290-4C96-B5B1-4B0711BABAF2}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.TemplateTaskGenerator", "TemplateTaskGenerator\PARR.TemplateTaskGenerator.csproj", "{D4C51090-CE06-4158-9A0E-961744872411}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.TemplateTaskGeneratorWorker", "TemplateTaskGeneratorWorker\PARR.TemplateTaskGeneratorWorker.csproj", "{93249642-DF7D-41A1-87C0-6E3BAECB43EC}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -256,6 +260,14 @@ Global
|
|||||||
{17245D0B-3290-4C96-B5B1-4B0711BABAF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{17245D0B-3290-4C96-B5B1-4B0711BABAF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{17245D0B-3290-4C96-B5B1-4B0711BABAF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{17245D0B-3290-4C96-B5B1-4B0711BABAF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{17245D0B-3290-4C96-B5B1-4B0711BABAF2}.Release|Any CPU.Build.0 = Release|Any CPU
|
{17245D0B-3290-4C96-B5B1-4B0711BABAF2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D4C51090-CE06-4158-9A0E-961744872411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D4C51090-CE06-4158-9A0E-961744872411}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D4C51090-CE06-4158-9A0E-961744872411}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D4C51090-CE06-4158-9A0E-961744872411}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{93249642-DF7D-41A1-87C0-6E3BAECB43EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{93249642-DF7D-41A1-87C0-6E3BAECB43EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{93249642-DF7D-41A1-87C0-6E3BAECB43EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{93249642-DF7D-41A1-87C0-6E3BAECB43EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
13
PARR.BLL/Domain/Mq/TemplateTaskGeneratorMq.cs
Normal file
13
PARR.BLL/Domain/Mq/TemplateTaskGeneratorMq.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace PARR.BLL.Domain.Mq
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Модель в MQ, генератора заданий на генерацию шаблонов
|
||||||
|
/// </summary>
|
||||||
|
public class TemplateTaskGeneratorMq
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Id регламентной работы
|
||||||
|
/// </summary>
|
||||||
|
public Guid JobId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -76,6 +76,6 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Генератор Template
|
/// Генератор Template
|
||||||
/// </summary>
|
/// </summary>
|
||||||
TemplateGenerator = 13
|
TemplateTaskGenerator = 13
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.BLL.Domain.Mq;
|
using PARR.BLL.Domain.Mq;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
using PARR.Constants;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace PARR.TemplateActivator;
|
namespace PARR.TemplateActivator;
|
||||||
|
|
||||||
@@ -67,6 +65,6 @@ internal class MqTemplateActivator : IMqTemplateActivator
|
|||||||
|
|
||||||
public async Task StopAsync()
|
public async Task StopAsync()
|
||||||
{
|
{
|
||||||
await mqService.DisposeAsync();
|
await mqService.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.Constants;
|
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
|
||||||
namespace PARR.TemplateActivator;
|
namespace PARR.TemplateActivator;
|
||||||
|
|||||||
8
TemplateTaskGenerator/IMqTemplateTaskGenerator.cs
Normal file
8
TemplateTaskGenerator/IMqTemplateTaskGenerator.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace PARR.TemplateTaskGenerator
|
||||||
|
{
|
||||||
|
public interface IMqTemplateTaskGenerator
|
||||||
|
{
|
||||||
|
Task StartAsync();
|
||||||
|
Task StopAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
7
TemplateTaskGenerator/ITemplateTaskGenerator.cs
Normal file
7
TemplateTaskGenerator/ITemplateTaskGenerator.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PARR.TemplateTaskGenerator
|
||||||
|
{
|
||||||
|
internal interface ITemplateTaskGenerator
|
||||||
|
{
|
||||||
|
Task GenerateTemplateTaskAsync(Guid jobId);
|
||||||
|
}
|
||||||
|
}
|
||||||
79
TemplateTaskGenerator/MqTemplateTaskGenerator.cs
Normal file
79
TemplateTaskGenerator/MqTemplateTaskGenerator.cs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PARR.BLL.Domain.Mq;
|
||||||
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.TemplateTaskGenerator.Services;
|
||||||
|
using PARR.TemplateTaskGenerator.Settings;
|
||||||
|
|
||||||
|
namespace PARR.TemplateTaskGenerator
|
||||||
|
{
|
||||||
|
internal class MqTemplateTaskGenerator : IMqTemplateTaskGenerator
|
||||||
|
{
|
||||||
|
private readonly ILogger<MqTemplateTaskGenerator> logger;
|
||||||
|
private readonly MqSettings mqSettings;
|
||||||
|
private readonly IMqService mqService;
|
||||||
|
private readonly ITransformService transformService;
|
||||||
|
private readonly IServiceProvider serviceProvider;
|
||||||
|
|
||||||
|
public MqTemplateTaskGenerator(
|
||||||
|
ILogger<MqTemplateTaskGenerator> logger,
|
||||||
|
MqSettings mqSettings,
|
||||||
|
IMqService mqService,
|
||||||
|
ITransformService transformService,
|
||||||
|
IServiceProvider serviceProvider
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this.mqSettings = mqSettings;
|
||||||
|
this.mqService = mqService;
|
||||||
|
this.transformService = transformService;
|
||||||
|
this.serviceProvider = serviceProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task StartAsync()
|
||||||
|
{
|
||||||
|
var isConnected = await mqService.InitConsumerAsync(mqSettings.TemplateTaskGenerator, GenerateTemplateTaskAsync);
|
||||||
|
|
||||||
|
if (!isConnected)
|
||||||
|
throw new Exception("Ошибка при подключении к RabbitMq");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task StopAsync()
|
||||||
|
{
|
||||||
|
await mqService.DisposeAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task GenerateTemplateTaskAsync(string msg)
|
||||||
|
{
|
||||||
|
logger.LogInformation($"Получили запрос: {msg}");
|
||||||
|
|
||||||
|
var query = transformService.GetModelFromJson<TemplateTaskGeneratorMq>(msg);
|
||||||
|
if (query == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
await using (var scope = serviceProvider.CreateAsyncScope())
|
||||||
|
{
|
||||||
|
var validatorService = GetServiceInScope<IValidatorService>(scope);
|
||||||
|
if (!await validatorService.IsValidAsync(query.JobId))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var templateTaskGenerator = GetServiceInScope<ITemplateTaskGenerator>(scope);
|
||||||
|
await templateTaskGenerator.GenerateTemplateTaskAsync(query.JobId);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Service GetServiceInScope<Service>(IServiceScope scope)
|
||||||
|
{
|
||||||
|
var service = scope.ServiceProvider.GetService<Service>();
|
||||||
|
if (service == null)
|
||||||
|
throw new Exception($"Не найден сервис: {nameof(Service)}");
|
||||||
|
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
TemplateTaskGenerator/PARR.TemplateTaskGenerator.csproj
Normal file
14
TemplateTaskGenerator/PARR.TemplateTaskGenerator.csproj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
|
||||||
|
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
12
TemplateTaskGenerator/Services/IValidatorService.cs
Normal file
12
TemplateTaskGenerator/Services/IValidatorService.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace PARR.TemplateTaskGenerator.Services
|
||||||
|
{
|
||||||
|
internal interface IValidatorService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Проверяет существование регламентной работы
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="jobId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> IsValidAsync(Guid jobId);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
TemplateTaskGenerator/Services/ValidatorService.cs
Normal file
36
TemplateTaskGenerator/Services/ValidatorService.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PARR.DAL.Services.Interfaces.Job;
|
||||||
|
|
||||||
|
namespace PARR.TemplateTaskGenerator.Services
|
||||||
|
{
|
||||||
|
internal class ValidatorService : IValidatorService
|
||||||
|
{
|
||||||
|
private readonly ILogger<ValidatorService> logger;
|
||||||
|
private readonly IJobService jobService;
|
||||||
|
|
||||||
|
|
||||||
|
public ValidatorService(
|
||||||
|
ILogger<ValidatorService> logger,
|
||||||
|
IJobService jobService
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this.jobService = jobService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<bool> IsValidAsync(Guid jobId)
|
||||||
|
{
|
||||||
|
var isExist = await jobService.GetAsync(jobId);
|
||||||
|
|
||||||
|
if (isExist == null)
|
||||||
|
{
|
||||||
|
logger.LogError($"Не найдена регалментная работа {nameof(jobId)}: {jobId}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
30
TemplateTaskGenerator/Settings/MqSettings.cs
Normal file
30
TemplateTaskGenerator/Settings/MqSettings.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using PARR.BLL.Contracts.Interfaces;
|
||||||
|
|
||||||
|
namespace PARR.TemplateTaskGenerator.Settings
|
||||||
|
{
|
||||||
|
internal class MqSettings
|
||||||
|
{
|
||||||
|
public TemplateTaskGenerator TemplateTaskGenerator { get; set; } = new TemplateTaskGenerator();
|
||||||
|
public TemplateGeneratorWorker TemplateGeneratorWorker { get; set; } = new TemplateGeneratorWorker();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal class TemplateTaskGenerator : IMqSettings
|
||||||
|
{
|
||||||
|
public string HostName { get; set; } = string.Empty;
|
||||||
|
public string QueueName { get; set; } = string.Empty;
|
||||||
|
public string User { get; set; } = string.Empty;
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
public ushort? PrefetchCount { get; set; } = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal class TemplateGeneratorWorker : IMqSettings
|
||||||
|
{
|
||||||
|
public string HostName { get; set; } = string.Empty;
|
||||||
|
public string QueueName { get; set; } = string.Empty;
|
||||||
|
public string User { get; set; } = string.Empty;
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
public ushort? PrefetchCount { get; set; } = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
60
TemplateTaskGenerator/TemplateTaskGenerator.cs
Normal file
60
TemplateTaskGenerator/TemplateTaskGenerator.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PARR.BLL.Domain.Mq;
|
||||||
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Common.Domain;
|
||||||
|
using PARR.Constants;
|
||||||
|
using PARR.DAL.DomainServices.Interfaces;
|
||||||
|
using PARR.TemplateTaskGenerator.Settings;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace PARR.TemplateTaskGenerator
|
||||||
|
{
|
||||||
|
internal class TemplateTaskGenerator : ITemplateTaskGenerator
|
||||||
|
{
|
||||||
|
private readonly ILogger<TemplateTaskGenerator> logger;
|
||||||
|
private readonly IUnitFilterService unitFilterService;
|
||||||
|
private readonly MqSettings mqSettings;
|
||||||
|
private readonly IMqService mqService;
|
||||||
|
|
||||||
|
public TemplateTaskGenerator(
|
||||||
|
ILogger<TemplateTaskGenerator> logger,
|
||||||
|
IUnitFilterService unitFilterService,
|
||||||
|
MqSettings mqSettings,
|
||||||
|
IMqService mqService
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this.unitFilterService = unitFilterService;
|
||||||
|
this.mqSettings = mqSettings;
|
||||||
|
this.mqService = mqService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task GenerateTemplateTaskAsync(Guid jobId)
|
||||||
|
{
|
||||||
|
var unitIdsToCreateTemplate = await unitFilterService.GetUnitsIdForNotExistTemplatesByJobFilterAsync(jobId);
|
||||||
|
|
||||||
|
if (unitIdsToCreateTemplate == null || !unitIdsToCreateTemplate.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var unitId in unitIdsToCreateTemplate)
|
||||||
|
{
|
||||||
|
var mqRequest = new TemplateGeneratorWorkerMq
|
||||||
|
{
|
||||||
|
JobId = jobId,
|
||||||
|
UnitId = unitId,
|
||||||
|
HistoryInitiator = new HistoryInitiator { InitiatorComment = "Запрос на создание шаблона", InitiatorParrComponentId = ParrComponentsEnum.TemplateTaskGenerator }
|
||||||
|
};
|
||||||
|
|
||||||
|
var msg = JsonSerializer.Serialize(mqRequest);
|
||||||
|
|
||||||
|
var result = await mqService.SendAsync(mqSettings.TemplateGeneratorWorker, new[] { msg });
|
||||||
|
|
||||||
|
if (result.IsSuccess)
|
||||||
|
logger.LogInformation($"Отправлен запрос на создание шаблона: {msg}");
|
||||||
|
else
|
||||||
|
logger.LogError($"Ошибка при отправке запроса на создание шаблона: {msg}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
TemplateTaskGenerator/TemplateTaskGeneratorInstaller.cs
Normal file
38
TemplateTaskGenerator/TemplateTaskGeneratorInstaller.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using PARR.BLL;
|
||||||
|
using PARR.DAL;
|
||||||
|
using PARR.TemplateTaskGenerator.Services;
|
||||||
|
using PARR.TemplateTaskGenerator.Settings;
|
||||||
|
|
||||||
|
namespace PARR.TemplateTaskGenerator
|
||||||
|
{
|
||||||
|
public static class TemplateTaskGeneratorInstaller
|
||||||
|
{
|
||||||
|
public static void InstallTemplateTaskGeneratorSerivces(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
services.InstallBllServices(configuration);
|
||||||
|
services.InstallDalServices(configuration);
|
||||||
|
|
||||||
|
var mqSettings = new MqSettings();
|
||||||
|
configuration.GetSection(nameof(MqSettings)).Bind(mqSettings);
|
||||||
|
services.AddSingleton(mqSettings);
|
||||||
|
|
||||||
|
services.AddTransient<IMqTemplateTaskGenerator, MqTemplateTaskGenerator>();
|
||||||
|
services.AddTransient<IValidatorService, ValidatorService>();
|
||||||
|
services.AddTransient<ITemplateTaskGenerator, TemplateTaskGenerator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IConfigurationBuilder AddTemplateTaskGeneratorConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
|
||||||
|
{
|
||||||
|
builder.AddDalConfigurations(services);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddTemplateTaskGeneratorSettings(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
services.AddDallSettings(configuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<UserSecretsId>dotnet-TemplateTaskGeneratorWorker-31809d29-599f-4a6d-8700-45ea8d9e7649</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.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TemplateTaskGenerator\PARR.TemplateTaskGenerator.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
31
TemplateTaskGeneratorWorker/Program.cs
Normal file
31
TemplateTaskGeneratorWorker/Program.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using Elastic.CommonSchema.Serilog;
|
||||||
|
using PARR.TemplateTaskGenerator;
|
||||||
|
using PARR.TemplateTaskGeneratorWorker;
|
||||||
|
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.InstallTemplateTaskGeneratorSerivces(builder.Configuration);
|
||||||
|
builder.Configuration.AddTemplateTaskGeneratorConfigurations(builder.Services);
|
||||||
|
builder.Services.AddTemplateTaskGeneratorSettings(builder.Configuration);
|
||||||
|
|
||||||
|
builder.Services.AddHostedService<Worker>();
|
||||||
|
|
||||||
|
var host = builder.Build();
|
||||||
|
host.Run();
|
||||||
11
TemplateTaskGeneratorWorker/Properties/launchSettings.json
Normal file
11
TemplateTaskGeneratorWorker/Properties/launchSettings.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"TemplateTaskGeneratorWorker": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"DOTNET_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
32
TemplateTaskGeneratorWorker/Worker.cs
Normal file
32
TemplateTaskGeneratorWorker/Worker.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using PARR.TemplateTaskGenerator;
|
||||||
|
|
||||||
|
namespace PARR.TemplateTaskGeneratorWorker
|
||||||
|
{
|
||||||
|
public class Worker : BackgroundService
|
||||||
|
{
|
||||||
|
private readonly ILogger<Worker> _logger;
|
||||||
|
private readonly IMqTemplateTaskGenerator mqTemplateTaskGenerator;
|
||||||
|
|
||||||
|
public Worker(
|
||||||
|
ILogger<Worker> logger,
|
||||||
|
IMqTemplateTaskGenerator mqTemplateTaskGenerator
|
||||||
|
)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
this.mqTemplateTaskGenerator = mqTemplateTaskGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
await mqTemplateTaskGenerator.StartAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
mqTemplateTaskGenerator.StopAsync().Wait();
|
||||||
|
|
||||||
|
return base.StopAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
TemplateTaskGeneratorWorker/appsettings.Development.json
Normal file
12
TemplateTaskGeneratorWorker/appsettings.Development.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"MqSettings": {
|
||||||
|
"TemplateTaskGenerator": { "HostName": "10.99.253.216" },
|
||||||
|
"TemplateGeneratorWorker": { "HostName": "10.99.253.216" }
|
||||||
|
}
|
||||||
|
}
|
||||||
45
TemplateTaskGeneratorWorker/appsettings.json
Normal file
45
TemplateTaskGeneratorWorker/appsettings.json
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"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.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Serilog": {
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Debug",
|
||||||
|
"Override": {
|
||||||
|
"Microsoft": "Warning",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Debug"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "log/log-.txt",
|
||||||
|
"rollingInterval": "Day"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"MqSettings": {
|
||||||
|
"TemplateTaskGenerator": {
|
||||||
|
"HostName": "parr-rabbitmq",
|
||||||
|
"QueueName": "parr-template-task-generator",
|
||||||
|
"User": "template_task_generator_reader",
|
||||||
|
"Password": "wzqj$Z@3:poz@oot"
|
||||||
|
},
|
||||||
|
"TemplateGeneratorWorker": {
|
||||||
|
"HostName": "parr-rabbitmq",
|
||||||
|
"QueueName": "parr-template-generator",
|
||||||
|
"User": "template_generator_writer",
|
||||||
|
"Password": "B;6h+yF$zQ0OSkLX"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user