This commit is contained in:
@@ -4,6 +4,7 @@ WORKDIR /src
|
||||
|
||||
COPY Jobs/cv-cleanup-job/cv-cleanup-job.csproj Jobs/cv-cleanup-job/
|
||||
COPY Jobs/job-scheduler/job-scheduler.csproj Jobs/job-scheduler/
|
||||
COPY Helpers/startup-helpers/startup-helpers.csproj Helpers/startup-helpers/
|
||||
COPY Apis/api-models/api-models.csproj Apis/api-models/
|
||||
COPY Apis/shared-models/shared-models.csproj Apis/shared-models/
|
||||
|
||||
@@ -11,6 +12,7 @@ RUN dotnet restore Jobs/cv-cleanup-job/cv-cleanup-job.csproj
|
||||
|
||||
COPY Jobs/cv-cleanup-job/ Jobs/cv-cleanup-job/
|
||||
COPY Jobs/job-scheduler/ Jobs/job-scheduler/
|
||||
COPY Helpers/startup-helpers/ Helpers/startup-helpers/
|
||||
COPY Apis/api-models/ Apis/api-models/
|
||||
COPY Apis/shared-models/ Apis/shared-models/
|
||||
|
||||
|
||||
@@ -1,21 +1,47 @@
|
||||
using System.Reflection;
|
||||
using CvCleanupJob.Tasks;
|
||||
using JobScheduler.Scheduling;
|
||||
using JobScheduler.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Models.Settings;
|
||||
using Serilog;
|
||||
using StartupHelpers;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
const string ServiceName = "cv-cleanup-job";
|
||||
|
||||
builder.Services.Configure<FileStorageSettings>(builder.Configuration.GetSection("FileStorage"));
|
||||
StartupExtensions.LoadDotEnvFile();
|
||||
var appVersion = StartupExtensions.GetApplicationVersion(Assembly.GetExecutingAssembly());
|
||||
|
||||
builder.Services.AddSingleton<CvStorageCleanupJobTask>();
|
||||
builder.Services.AddSingleton<IEnumerable<IJobTask>>(sp => new IJobTask[]
|
||||
try
|
||||
{
|
||||
sp.GetRequiredService<CvStorageCleanupJobTask>(),
|
||||
});
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.Services.AddHostedService<JobSchedulerHostedService>();
|
||||
builder.ConfigureJsonSerilog(ServiceName, appVersion);
|
||||
Log.Information("Starting {Service} version {AppVersion}", ServiceName, appVersion);
|
||||
|
||||
var host = builder.Build();
|
||||
await host.RunAsync();
|
||||
builder.Services.Configure<FileStorageSettings>(builder.Configuration.GetSection("FileStorage"));
|
||||
|
||||
builder.Services.AddSingleton<CvStorageCleanupJobTask>();
|
||||
builder.Services.AddSingleton<IEnumerable<IJobTask>>(sp => new IJobTask[]
|
||||
{
|
||||
sp.GetRequiredService<CvStorageCleanupJobTask>(),
|
||||
});
|
||||
|
||||
builder.Services.AddHostedService<JobSchedulerHostedService>();
|
||||
|
||||
var host = builder.Build();
|
||||
|
||||
host.LogHostStartupDiagnostics(ServiceName);
|
||||
|
||||
Log.Information("{Service} startup complete. Background scheduler is running.", ServiceName);
|
||||
await host.RunAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "{Service} terminated unexpectedly", ServiceName);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,73 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [
|
||||
"Serilog.Sinks.Console",
|
||||
"Serilog.Sinks.File",
|
||||
"Serilog.Sinks.Email"
|
||||
],
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.Extensions.Hosting": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"System.Net.Http.HttpClient": "Warning",
|
||||
"CvCleanupJob": "Information",
|
||||
"JobScheduler": "Information"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Console",
|
||||
"Args": {
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {SourceContext}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "logs/cv-cleanup-job-.log",
|
||||
"rollingInterval": "Day",
|
||||
"retainedFileCountLimit": 30,
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {SourceContext}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Email",
|
||||
"Args": {
|
||||
"restrictedToMinimumLevel": "Error",
|
||||
"fromEmail": "",
|
||||
"toEmail": "",
|
||||
"mailServer": "",
|
||||
"networkCredential": {
|
||||
"userName": "",
|
||||
"password": ""
|
||||
},
|
||||
"port": 587,
|
||||
"enableSsl": true,
|
||||
"emailSubject": "[mihes.ro CV cleanup job] Error Alert",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}",
|
||||
"batchPostingLimit": 10,
|
||||
"period": "0.00:05:00"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [
|
||||
"FromLogContext",
|
||||
"WithMachineName",
|
||||
"WithEnvironmentName"
|
||||
]
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"Microsoft.Extensions.Hosting": "Information",
|
||||
"CvCleanupJob": "Information",
|
||||
"JobScheduler": "Information"
|
||||
}
|
||||
},
|
||||
"LogEnvironmentOnStartup": true,
|
||||
"FileStorage": {
|
||||
"Path": "Files"
|
||||
},
|
||||
|
||||
@@ -12,8 +12,13 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="logs\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Apis\api-models\api-models.csproj" />
|
||||
<ProjectReference Include="..\..\Helpers\startup-helpers\startup-helpers.csproj" />
|
||||
<ProjectReference Include="..\job-scheduler\job-scheduler.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user