feat(jobAutoControl): логика управления авто-контролем
This commit is contained in:
16
PARR.API.sln
16
PARR.API.sln
@@ -72,9 +72,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.TemplateDistributor",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.TemplateDistributorWorker", "PARR.TemplateDistributorWorker\PARR.TemplateDistributorWorker.csproj", "{89155CAB-295D-4937-8B7A-05170587A2BC}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.TemplateDistributorWorker", "PARR.TemplateDistributorWorker\PARR.TemplateDistributorWorker.csproj", "{89155CAB-295D-4937-8B7A-05170587A2BC}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.TemplateActivator", "PARR.TemplateActivator\PARR.TemplateActivator.csproj", "{C92621CD-EC6A-4788-94CF-D03C0A386F12}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.TemplateActivator", "PARR.TemplateActivator\PARR.TemplateActivator.csproj", "{C92621CD-EC6A-4788-94CF-D03C0A386F12}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.TemplateActivatorWorker", "PARR.TemplateActivatorWorker\PARR.TemplateActivatorWorker.csproj", "{97E096AA-26F3-417A-A969-381464F4EF43}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.TemplateActivatorWorker", "PARR.TemplateActivatorWorker\PARR.TemplateActivatorWorker.csproj", "{97E096AA-26F3-417A-A969-381464F4EF43}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.JobAutoControlWorker", "PARR.JobAutoControlWorker\PARR.JobAutoControlWorker.csproj", "{EFDC0833-E79C-476B-BF91-58E8778EA2E2}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.JobAutoControl", "PARR.JobAutoControl\PARR.JobAutoControl.csproj", "{2C35CCD5-6DCD-4640-98DA-D2DC11CE3BA5}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -208,6 +212,14 @@ Global
|
|||||||
{97E096AA-26F3-417A-A969-381464F4EF43}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{97E096AA-26F3-417A-A969-381464F4EF43}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{97E096AA-26F3-417A-A969-381464F4EF43}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{97E096AA-26F3-417A-A969-381464F4EF43}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{97E096AA-26F3-417A-A969-381464F4EF43}.Release|Any CPU.Build.0 = Release|Any CPU
|
{97E096AA-26F3-417A-A969-381464F4EF43}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{EFDC0833-E79C-476B-BF91-58E8778EA2E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{EFDC0833-E79C-476B-BF91-58E8778EA2E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{EFDC0833-E79C-476B-BF91-58E8778EA2E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{EFDC0833-E79C-476B-BF91-58E8778EA2E2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{2C35CCD5-6DCD-4640-98DA-D2DC11CE3BA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{2C35CCD5-6DCD-4640-98DA-D2DC11CE3BA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{2C35CCD5-6DCD-4640-98DA-D2DC11CE3BA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{2C35CCD5-6DCD-4640-98DA-D2DC11CE3BA5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
Import System.Runtime.InteropServices
|
|
||||||
|
|
||||||
' In SDK-style projects such as this one, several assembly attributes that were historically
|
|
||||||
' defined in this file are now automatically added during build and populated with
|
|
||||||
' values defined in project properties. For details of which attributes are included
|
|
||||||
' and how to customise this process see: https://aka.ms/assembly-info-properties
|
|
||||||
|
|
||||||
|
|
||||||
' Setting ComVisible to false makes the types in this assembly not visible to COM
|
|
||||||
' components. If you need to access a type in this assembly from COM, set the ComVisible
|
|
||||||
' attribute to true on that type.
|
|
||||||
|
|
||||||
<Assembly: ComVisible(False)>
|
|
||||||
|
|
||||||
' The following GUID is for the ID of the typelib if this project is exposed to COM.
|
|
||||||
|
|
||||||
<Assembly: Guid("b369a17a-5b45-4482-9c44-bceb865427d2")>
|
|
||||||
7
PARR.JobAutoControl/IJobAutoControlManager.cs
Normal file
7
PARR.JobAutoControl/IJobAutoControlManager.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PARR.JobAutoControl
|
||||||
|
{
|
||||||
|
public interface IJobAutoControlManager
|
||||||
|
{
|
||||||
|
Task StartAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
44
PARR.JobAutoControl/JobAutoControlInstaller.cs
Normal file
44
PARR.JobAutoControl/JobAutoControlInstaller.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using PARR.BLL;
|
||||||
|
using PARR.DAL;
|
||||||
|
using PARR.JobAutoControl.Settings;
|
||||||
|
|
||||||
|
namespace PARR.JobAutoControl
|
||||||
|
{
|
||||||
|
public static class JobAutoControlInstaller
|
||||||
|
{
|
||||||
|
|
||||||
|
public static void InstallJobAutoControlServices(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
services.InstallDalServices(configuration);
|
||||||
|
services.InstallBllServices(configuration);
|
||||||
|
|
||||||
|
var settings = new WorkerSettings();
|
||||||
|
configuration.GetSection(nameof(WorkerSettings)).Bind(settings);
|
||||||
|
services.AddSingleton(settings);
|
||||||
|
|
||||||
|
var mqSettings = new MqSettings();
|
||||||
|
configuration.GetSection(nameof(MqSettings)).Bind(mqSettings);
|
||||||
|
services.AddSingleton(mqSettings);
|
||||||
|
|
||||||
|
|
||||||
|
services.AddTransient<IJobAutoControlManager, JobAutoControlManager>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static IConfigurationBuilder AddJobAutoControlConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
|
||||||
|
{
|
||||||
|
builder.AddDalConfigurations(services);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void AddJobAutoControlSettings(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
services.AddDallSettings(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
194
PARR.JobAutoControl/JobAutoControlManager.cs
Normal file
194
PARR.JobAutoControl/JobAutoControlManager.cs
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PARR.BLL.Domain.Mq;
|
||||||
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Constants;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
using PARR.JobAutoControl.Settings;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace PARR.JobAutoControl
|
||||||
|
{
|
||||||
|
internal class JobAutoControlManager : IJobAutoControlManager
|
||||||
|
{
|
||||||
|
private readonly WorkerSettings workerSettings;
|
||||||
|
private readonly ILogger<JobAutoControlManager> logger;
|
||||||
|
private readonly IIntervalService intervalService;
|
||||||
|
private readonly IServiceProvider serviceProvider;
|
||||||
|
private readonly MqSettings mqSettings;
|
||||||
|
|
||||||
|
public JobAutoControlManager(
|
||||||
|
WorkerSettings workerSettings,
|
||||||
|
ILogger<JobAutoControlManager> logger,
|
||||||
|
IIntervalService intervalService,
|
||||||
|
IServiceProvider serviceProvider,
|
||||||
|
MqSettings mqSettings
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.workerSettings = workerSettings;
|
||||||
|
this.logger = logger;
|
||||||
|
this.intervalService = intervalService;
|
||||||
|
this.serviceProvider = serviceProvider;
|
||||||
|
this.mqSettings = mqSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task StartAsync()
|
||||||
|
{
|
||||||
|
logger.LogInformation("Запуск сервиса управления авто-контролем РР (JobAutoControl)");
|
||||||
|
|
||||||
|
await intervalService.IntervalInitAsync(async () =>
|
||||||
|
{
|
||||||
|
using (var scope = serviceProvider.CreateScope())
|
||||||
|
{
|
||||||
|
var jobAutoControlService = scope.ServiceProvider.GetService<IJobAutoControlService>();
|
||||||
|
var mqService = scope.ServiceProvider.GetService<IMqService>();
|
||||||
|
|
||||||
|
if (jobAutoControlService == null || mqService == null)
|
||||||
|
throw new Exception($"Не смог получить серивс {nameof(IJobAutoControlService)} или {nameof(IMqService)}");
|
||||||
|
|
||||||
|
await HandlerAsync(jobAutoControlService, mqService);
|
||||||
|
}
|
||||||
|
}, workerSettings.RepeatEvery);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task HandlerAsync(IJobAutoControlService jobAutoControlService, IMqService mqService)
|
||||||
|
{
|
||||||
|
await GenerateAsync(jobAutoControlService, mqService);
|
||||||
|
await DeactivateAsync(jobAutoControlService, mqService);
|
||||||
|
await ActivateAsync(jobAutoControlService, mqService);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Генерировать новые РР
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="jobAutoControlService"></param>
|
||||||
|
/// <param name="mqService"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task GenerateAsync(IJobAutoControlService jobAutoControlService, IMqService mqService)
|
||||||
|
{
|
||||||
|
var jobsToGenerate = await jobAutoControlService.Get()
|
||||||
|
.Include(t => t.JobEkMasks)
|
||||||
|
.Include(t => t.JobAutoControlInEkStatuses)
|
||||||
|
.Include(t => t.ApplicationsInWork)
|
||||||
|
.Where(t => t.CreateNew && t.JobEkMasks.Any() && t.JobAutoControlInEkStatuses.Any())
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
logger.LogInformation($"Найдено РР с включенным авто-контролем для генерации шаблонов и расписаний: {jobsToGenerate.Count()} шт.");
|
||||||
|
|
||||||
|
if (!jobsToGenerate.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
jobsToGenerate.ForEach(job =>
|
||||||
|
{
|
||||||
|
job.JobEkMasks.ToList().ForEach(ek =>
|
||||||
|
{
|
||||||
|
job.JobAutoControlInEkStatuses.ToList().ForEach(ekStatus =>
|
||||||
|
{
|
||||||
|
var request = new GeneratorTemplateMq
|
||||||
|
{
|
||||||
|
Action = "create",
|
||||||
|
ApplicationId = job.ApplicationsInWork!.ApplicationId,
|
||||||
|
Ek = ek.Name,
|
||||||
|
WorkId = job.ApplicationsInWork!.WorkId,
|
||||||
|
StatusEk = ekStatus.EkStatusCode,
|
||||||
|
IsActiveTemplate = job.OnTemplateIsActive,
|
||||||
|
IsActiveSchedule = job.OnScheduleIsActive
|
||||||
|
};
|
||||||
|
|
||||||
|
var msg = JsonSerializer.Serialize(request);
|
||||||
|
|
||||||
|
var result = mqService.Send(mqSettings.Generator, new[] { msg });
|
||||||
|
|
||||||
|
if (result.IsSuccess)
|
||||||
|
logger.LogInformation($"Отправлен запрос на генерацию: {msg}");
|
||||||
|
else
|
||||||
|
logger.LogError($"Ошибка при отправке запроса на генерацию: {msg}");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Деактивировать РР
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="jobAutoControlService"></param>
|
||||||
|
/// <param name="mqService"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task DeactivateAsync(IJobAutoControlService jobAutoControlService, IMqService mqService)
|
||||||
|
{
|
||||||
|
var jobsToDeactivate = await jobAutoControlService.Get()
|
||||||
|
.Include(t => t.JobEkMasks)
|
||||||
|
.Include(t => t.JobAutoControlInEkStatuses)
|
||||||
|
.Where(t => t.Deactivate && t.JobEkMasks.Any() && t.JobAutoControlInEkStatuses.Any())
|
||||||
|
.Select(t => t.ApplicationInWorkId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
logger.LogInformation($"Найдено РР с включенным авто-контролем для деактивации шаблонов и расписаний: {jobsToDeactivate.Count()} шт.");
|
||||||
|
|
||||||
|
if (!jobsToDeactivate.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
jobsToDeactivate.ForEach(applicationInWorkId =>
|
||||||
|
{
|
||||||
|
var request = new TemplateActivatorMq
|
||||||
|
{
|
||||||
|
Action = TemplateActivatorActionsEnum.DeactivateAllForAutoControl,
|
||||||
|
ApplicationInWorkId = applicationInWorkId
|
||||||
|
};
|
||||||
|
|
||||||
|
var msg = JsonSerializer.Serialize(request);
|
||||||
|
|
||||||
|
var result = mqService.Send(mqSettings.Activator, new[] { msg });
|
||||||
|
|
||||||
|
if (result.IsSuccess)
|
||||||
|
logger.LogInformation($"Отправлен запрос на деактивацию: {msg}");
|
||||||
|
else
|
||||||
|
logger.LogError($"Ошибка при отправке запроса на деактивацию: {msg}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Активировать РР
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="jobAutoControlService"></param>
|
||||||
|
/// <param name="mqService"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task ActivateAsync(IJobAutoControlService jobAutoControlService, IMqService mqService)
|
||||||
|
{
|
||||||
|
var jobsToActivate = await jobAutoControlService.Get()
|
||||||
|
.Include(t => t.JobEkMasks)
|
||||||
|
.Include(t => t.JobAutoControlInEkStatuses)
|
||||||
|
.Where(t => t.Activate && t.JobEkMasks.Any() && t.JobAutoControlInEkStatuses.Any())
|
||||||
|
.Select(t => t.ApplicationInWorkId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
if (!jobsToActivate.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
jobsToActivate.ForEach(applicationInWorkId =>
|
||||||
|
{
|
||||||
|
var request = new TemplateActivatorMq
|
||||||
|
{
|
||||||
|
Action = TemplateActivatorActionsEnum.ActivateAllForAutoControl,
|
||||||
|
ApplicationInWorkId = applicationInWorkId
|
||||||
|
};
|
||||||
|
|
||||||
|
var msg = JsonSerializer.Serialize(request);
|
||||||
|
|
||||||
|
var result = mqService.Send(mqSettings.Activator, new[] { msg });
|
||||||
|
|
||||||
|
if (result.IsSuccess)
|
||||||
|
logger.LogInformation($"Отправлен запрос на активацию: {msg}");
|
||||||
|
else
|
||||||
|
logger.LogError($"Ошибка при отправке запроса на активацию: {msg}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,4 +6,10 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
|
||||||
|
<ProjectReference Include="..\PARR.Constants\PARR.Constants.csproj" />
|
||||||
|
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
28
PARR.JobAutoControl/Settings/MqSettings.cs
Normal file
28
PARR.JobAutoControl/Settings/MqSettings.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using PARR.BLL.Contracts.Interfaces;
|
||||||
|
|
||||||
|
namespace PARR.JobAutoControl.Settings
|
||||||
|
{
|
||||||
|
internal class MqSettings
|
||||||
|
{
|
||||||
|
public Generator Generator { get; set; }
|
||||||
|
public Activator Activator { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class Generator : 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class Activator : 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
7
PARR.JobAutoControl/Settings/WorkerSettings.cs
Normal file
7
PARR.JobAutoControl/Settings/WorkerSettings.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PARR.JobAutoControl.Settings
|
||||||
|
{
|
||||||
|
internal class WorkerSettings
|
||||||
|
{
|
||||||
|
public TimeSpan RepeatEvery { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
28
PARR.JobAutoControlWorker/Dockerfile
Normal file
28
PARR.JobAutoControlWorker/Dockerfile
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#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.
|
||||||
|
|
||||||
|
FROM 10.99.253.167:8090/dotnet/runtime:7.0 AS base
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
FROM 10.99.253.167:8090/dotnet/sdk:7.0 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["NuGet.config", "."]
|
||||||
|
COPY ["PARR.JobAutoControlWorker/PARR.JobAutoControlWorker.csproj", "PARR.JobAutoControlWorker/"]
|
||||||
|
COPY ["PARR.JobAutoControl/PARR.JobAutoControl.csproj", "PARR.JobAutoControl/"]
|
||||||
|
COPY ["PARR.BLL/PARR.BLL.csproj", "PARR.BLL/"]
|
||||||
|
COPY ["PARR.Constants/PARR.Constants.csproj", "PARR.Constants/"]
|
||||||
|
COPY ["PARR.DAL/PARR.DAL.csproj", "PARR.DAL/"]
|
||||||
|
RUN dotnet restore "./PARR.JobAutoControlWorker/PARR.JobAutoControlWorker.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/PARR.JobAutoControlWorker"
|
||||||
|
RUN dotnet build "./PARR.JobAutoControlWorker.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
ARG app_version=0.0.0-default
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "./PARR.JobAutoControlWorker.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:Version=$app_version
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "PARR.JobAutoControlWorker.dll"]
|
||||||
@@ -5,9 +5,20 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<UserSecretsId>dotnet-PARR.JobAutoControlWorker-50dc4ed1-928f-47c3-855e-137f03acd19c</UserSecretsId>
|
<UserSecretsId>dotnet-PARR.JobAutoControlWorker-50dc4ed1-928f-47c3-855e-137f03acd19c</UserSecretsId>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.11.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PARR.JobAutoControl\PARR.JobAutoControl.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,10 +1,38 @@
|
|||||||
|
using Elastic.CommonSchema.Serilog;
|
||||||
|
using PARR.JobAutoControl;
|
||||||
using PARR.JobAutoControlWorker;
|
using PARR.JobAutoControlWorker;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
IHost host = Host.CreateDefaultBuilder(args)
|
var builder = Host.CreateApplicationBuilder();
|
||||||
.ConfigureServices(services =>
|
|
||||||
{
|
|
||||||
services.AddHostedService<Worker>();
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
|
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.InstallJobAutoControlServices(builder.Configuration);
|
||||||
|
builder.Configuration.AddJobAutoControlConfigurations(builder.Services);
|
||||||
|
builder.Services.AddJobAutoControlSettings(builder.Configuration);
|
||||||
|
|
||||||
|
|
||||||
|
builder.Services.AddHostedService<Worker>();
|
||||||
|
|
||||||
|
var host = builder.Build();
|
||||||
host.Run();
|
host.Run();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
{
|
{
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"PARR.JobAutoControlWorker": {
|
"PARR.JobAutoControlWorker": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"DOTNET_ENVIRONMENT": "Development"
|
"DOTNET_ENVIRONMENT": "Development"
|
||||||
}
|
},
|
||||||
|
"dotnetRunMessages": true
|
||||||
|
},
|
||||||
|
"Container (Dockerfile)": {
|
||||||
|
"commandName": "Docker"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,19 @@
|
|||||||
|
using PARR.JobAutoControl;
|
||||||
|
|
||||||
namespace PARR.JobAutoControlWorker
|
namespace PARR.JobAutoControlWorker
|
||||||
{
|
{
|
||||||
public class Worker : BackgroundService
|
public class Worker : BackgroundService
|
||||||
{
|
{
|
||||||
private readonly ILogger<Worker> _logger;
|
private readonly IJobAutoControlManager jobAutoControlManager;
|
||||||
|
|
||||||
public Worker(ILogger<Worker> logger)
|
public Worker(IJobAutoControlManager jobAutoControlManager)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
this.jobAutoControlManager = jobAutoControlManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
while (!stoppingToken.IsCancellationRequested)
|
await jobAutoControlManager.StartAsync();
|
||||||
{
|
|
||||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
|
||||||
await Task.Delay(1000, stoppingToken);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,13 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"MqSettings": {
|
||||||
|
"Generator": {
|
||||||
|
"HostName": "10.99.253.216"
|
||||||
|
},
|
||||||
|
"Activator": {
|
||||||
|
"HostName": "10.99.253.216"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,46 @@
|
|||||||
{
|
{
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;"
|
||||||
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.Hosting.Lifetime": "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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"WorkerSettings": {
|
||||||
|
"RepeatEvery": "6:00:00"
|
||||||
|
},
|
||||||
|
"MqSettings": {
|
||||||
|
"Generator": {
|
||||||
|
"HostName": "parr-rabbitmq",
|
||||||
|
"QueueName": "parr-generate-templates",
|
||||||
|
"User": "generate_templates_api",
|
||||||
|
"Password": "DHhjgdsf*&%95"
|
||||||
|
},
|
||||||
|
"Activator": {
|
||||||
|
"HostName": "parr-rabbitmq",
|
||||||
|
"QueueName": "parr-template-activator",
|
||||||
|
"User": "template_activator_writer",
|
||||||
|
"Password": "Gfkjhsdg*%fsdf"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,19 @@ namespace PARR.NextRun
|
|||||||
|
|
||||||
services.AddTransient<INextRunManager, NextRunManager>();
|
services.AddTransient<INextRunManager, NextRunManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static IConfigurationBuilder AddNextRunConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
|
||||||
|
{
|
||||||
|
builder.AddDalConfigurations(services);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void AddNextRunSettings(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
services.AddDallSettings(configuration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace PARR.NextRun
|
|||||||
var templateService = scope.ServiceProvider.GetService<ITemplateService>();
|
var templateService = scope.ServiceProvider.GetService<ITemplateService>();
|
||||||
|
|
||||||
if (templateService == null || esppSchService == null)
|
if (templateService == null || esppSchService == null)
|
||||||
throw new Exception("Не смог получить серивс ITemplateService или IEsppScheduleTransformService");
|
throw new Exception($"Не смог получить серивс {nameof(ITemplateService)} или {nameof(IEsppScheduleTransformService)}");
|
||||||
|
|
||||||
await HandlerAsync(templateService, esppSchService);
|
await HandlerAsync(templateService, esppSchService);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ builder.Services.AddLogging(config =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.InstallNextRunServices(builder.Configuration);
|
builder.Services.InstallNextRunServices(builder.Configuration);
|
||||||
|
builder.Configuration.AddNextRunConfigurations(builder.Services);
|
||||||
|
builder.Services.AddNextRunSettings(builder.Configuration);
|
||||||
|
|
||||||
builder.Services.AddHostedService<Worker>();
|
builder.Services.AddHostedService<Worker>();
|
||||||
|
|
||||||
var host = builder.Build();
|
var host = builder.Build();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
<None Include="docker-compose.espp-schedule-sync.yml" />
|
<None Include="docker-compose.espp-schedule-sync.yml" />
|
||||||
<None Include="docker-compose.espp-template-sync.yml" />
|
<None Include="docker-compose.espp-template-sync.yml" />
|
||||||
<None Include="docker-compose.generator-templates.yml" />
|
<None Include="docker-compose.generator-templates.yml" />
|
||||||
|
<None Include="docker-compose.job-auto-control.yml" />
|
||||||
<None Include="docker-compose.master.yml" />
|
<None Include="docker-compose.master.yml" />
|
||||||
<None Include="docker-compose.next-run.yml" />
|
<None Include="docker-compose.next-run.yml" />
|
||||||
<None Include="docker-compose.template-activator.yml" />
|
<None Include="docker-compose.template-activator.yml" />
|
||||||
|
|||||||
Reference in New Issue
Block a user