Added scheduler
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
<Using Include="Microsoft.Extensions.Logging" />
|
||||
<Using Include="Microsoft.Extensions.Options" />
|
||||
<Using Include="Microsoft.IdentityModel.Tokens" />
|
||||
<Using Include="Microsoft.FeatureManagement" />
|
||||
|
||||
<!-- Domain Constants -->
|
||||
<Using Static="true" Include="PostFundManagement.Domain.Extensions.Constants" />
|
||||
|
||||
@@ -4,7 +4,6 @@ using PostFundManagement.Domain.Abstractions;
|
||||
using PostFundManagement.Domain.Health;
|
||||
using PostFundManagement.Domain.Mediator;
|
||||
using PostFundManagement.Infrastructure.Database.Services;
|
||||
using static PostFundManagement.Domain.Extensions.Constants;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -45,7 +44,7 @@ builder.Services.AddSkorubaApiService(builder.Configuration);
|
||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(TelemetryPipelineBehavior<,>));
|
||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingPipelineBehavior<,>));
|
||||
|
||||
builder.Services.AddQuartzScheduler(DefaultSchedulerName, builder.Configuration);
|
||||
builder.Services.AddQuartzSchedulerClient(DefaultSchedulerName, builder.Configuration);
|
||||
builder.Services.AddEmailServices(builder.Configuration);
|
||||
builder.Services.AddHashServices(builder.Configuration);
|
||||
builder.Services.AddGarageS3(builder.Configuration);
|
||||
@@ -119,7 +118,9 @@ builder.Services.AddCors(options =>
|
||||
policy.SetIsOriginAllowed(origin =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(origin)) return false;
|
||||
|
||||
var clean = origin.TrimEnd('/');
|
||||
|
||||
if (allowedOrigins.Any(a => string.Equals(a.TrimEnd('/'), clean, StringComparison.OrdinalIgnoreCase)))
|
||||
return true;
|
||||
|
||||
@@ -133,10 +134,7 @@ builder.Services.AddCors(options =>
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore parse failure
|
||||
}
|
||||
catch { /* eat all exceptions */ }
|
||||
|
||||
return false;
|
||||
})
|
||||
|
||||
@@ -31,14 +31,7 @@
|
||||
"Microsoft.EntityFrameworkCore.Database": "Error",
|
||||
"Microsoft.EntityFrameworkCore.Update": "Error"
|
||||
}
|
||||
},
|
||||
"EmailProcessorCron": "0 */5 * * * ?",
|
||||
"Email": {
|
||||
"SmtpServer": "smtp.example.com",
|
||||
"SmtpPort": 587,
|
||||
"SenderEmail": "noreply@example.com",
|
||||
"SenderName": "Example"
|
||||
},
|
||||
},
|
||||
"HasherSettings": {
|
||||
"MinHashLength": 11
|
||||
},
|
||||
|
||||
@@ -9,4 +9,6 @@ public sealed class SmtpSettings
|
||||
public string? Host { get; set; }
|
||||
|
||||
public bool UseSsl { get; set; }
|
||||
|
||||
public string? ProcessorJobCron { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
|
||||
namespace PostFundManagement.Infrastructure.Database.Services;
|
||||
|
||||
public sealed class HeadlessTenantContextService : ITenantContextService
|
||||
{
|
||||
public string? TenantName => "Ifri Technologies";
|
||||
|
||||
public long TenantId => 1;
|
||||
|
||||
public bool ByPassTenantQueryFilter { get; set; } = true;
|
||||
|
||||
public bool IsAdmin => true;
|
||||
|
||||
public bool HasTenantFilter => true;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Stage 1: Runtime base
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
|
||||
USER app
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
|
||||
# Stage 2: Build & Restore
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
# Copy props and csproj files for layer caching
|
||||
COPY ["Directory.Build.props", "./"]
|
||||
COPY ["Directory.Packages.props", "./"]
|
||||
COPY ["PostFundManagement.snk", "./"]
|
||||
COPY ["LICENSE", "./"]
|
||||
COPY ["PostFundManagement.Jobs/PostFundManagement.Jobs.csproj", "PostFundManagement.Jobs/"]
|
||||
COPY ["PostFundManagement.Application/PostFundManagement.Application.csproj", "PostFundManagement.Application/"]
|
||||
COPY ["PostFundManagement.Domain/PostFundManagement.Domain.csproj", "PostFundManagement.Domain/"]
|
||||
COPY ["PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj", "PostFundManagement.Infrastructure/"]
|
||||
|
||||
# Restore packages
|
||||
RUN dotnet restore "PostFundManagement.Jobs/PostFundManagement.Jobs.csproj"
|
||||
|
||||
# Copy full source code
|
||||
COPY . .
|
||||
|
||||
# Build from the project folder using relative filename
|
||||
WORKDIR "/src/PostFundManagement.Jobs"
|
||||
RUN dotnet build "PostFundManagement.Jobs.csproj" -c Release -o /app/build
|
||||
|
||||
# Stage 3: Publish
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "PostFundManagement.Jobs.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# Stage 4: Final Runtime
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "PostFundManagement.Jobs.dll"]
|
||||
@@ -0,0 +1,21 @@
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
|
||||
namespace PostFundManagement.Jobs;
|
||||
|
||||
public class JobsWorker(IJobOrchestrator jobOrchestrator, IFeatureManager featureManager,
|
||||
ILogger<JobsWorker> logger) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
if(!await featureManager.IsEnabledAsync(nameof(JobsWorker)))
|
||||
{
|
||||
logger.LogInformation("JobsWorker is disabled.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: scheduler reccuring jobs
|
||||
|
||||
logger.LogInformation("JobsWorker is stopping.");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
@@ -7,6 +7,20 @@
|
||||
<UserSecretsId>dotnet-PostFundManagement.Jobs-97b98845-fddb-4212-b877-8dac9f7f86e3</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- File Nesting -->
|
||||
<ItemGroup>
|
||||
<ProjectCapability Include="ConfigurableFileNesting" />
|
||||
<ProjectCapability Include="ConfigurableFileNestingFeatureEnabled" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- CQRS Source Generator -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mediator.SourceGenerator">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,7 +1,38 @@
|
||||
using PostFundManagement.Application.Extensions;
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
using PostFundManagement.Domain.Mediator;
|
||||
using PostFundManagement.Infrastructure.Database.Services;
|
||||
using PostFundManagement.Jobs;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
builder.Services.AddFeatureManagement();
|
||||
|
||||
builder.Services.AddSharedServices();
|
||||
builder.Services.AddHostedService<JobsWorker>();
|
||||
builder.Services.AddRegisterServicesWithCaching(builder.Configuration);
|
||||
builder.Services.AddEndpointAndServiceCaching(builder.Configuration);
|
||||
builder.Services.AddTransient<ITenantContextService, HeadlessTenantContextService>();
|
||||
|
||||
builder.Services.AddMediator();
|
||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(TelemetryPipelineBehavior<,>));
|
||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingPipelineBehavior<,>));
|
||||
|
||||
builder.Services.AddQuartzScheduler(DefaultSchedulerName, builder.Configuration);
|
||||
builder.Services.AddEmailServices(builder.Configuration);
|
||||
builder.Services.AddHashServices(builder.Configuration);
|
||||
builder.Services.AddGarageS3(builder.Configuration);
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddDataProtectionDatabase(builder.Configuration);
|
||||
builder.Services.AddApplicationDbContext(builder.Configuration);
|
||||
|
||||
var host = builder.Build();
|
||||
|
||||
var schedulerFactory = host.Services.GetRequiredService<ISchedulerFactory>();
|
||||
var scheduler = await schedulerFactory.GetScheduler();
|
||||
|
||||
if (scheduler!.Status != SchedulerStatus.Running)
|
||||
await scheduler.Start();
|
||||
|
||||
host.Run();
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace PostFundManagement.Jobs
|
||||
{
|
||||
public class Worker(ILogger<Worker> logger) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
}
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,37 @@
|
||||
{
|
||||
"FeatureManagement": {
|
||||
"JobsWorker": true,
|
||||
"EmailProcessorJobEnabled": true,
|
||||
"ServiceCaching": false
|
||||
},
|
||||
"GeneralS3Settings": {
|
||||
"ServiceUrl": "https://s3.garage.khongisa.co.za",
|
||||
"Region": "garage",
|
||||
"BucketName": "pfm",
|
||||
"CdnBaseUrl": "https://pfm.cdn.khongisa.co.za"
|
||||
},
|
||||
"Monitoring": {
|
||||
"Address": "http://aspire-dashboard-service.aspire.svc.cluster.local:18889",
|
||||
"ServiceName": "Pfm.Jobs.DEV"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
"Default": "Warning",
|
||||
"Quartz": "Error",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore.Database": "Error",
|
||||
"Microsoft.EntityFrameworkCore.Update": "Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Email": {
|
||||
"ProcessorJobCron": "0 */5 * * * ?",
|
||||
"SmtpServer": "smtp.example.com",
|
||||
"SmtpPort": 587,
|
||||
"SenderEmail": "noreply@example.com",
|
||||
"SenderName": "Example"
|
||||
},
|
||||
"HasherSettings": {
|
||||
"MinHashLength": 11
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
+12
-6
@@ -1,4 +1,13 @@
|
||||
<Solution>
|
||||
<Folder Name="/Presentation/">
|
||||
<Project Path="PostFundManagement.Api/PostFundManagement.Api.csproj" />
|
||||
<Project Path="PostFundManagement.Jobs/PostFundManagement.Jobs.csproj" Id="81281806-b5ca-4784-87af-3e8feeac988c" />
|
||||
</Folder>
|
||||
<Folder Name="/Shared/">
|
||||
<Project Path="PostFundManagement.Application/PostFundManagement.Application.csproj" Id="750c7754-53a7-4573-abed-5c436246a04d" />
|
||||
<Project Path="PostFundManagement.Domain/PostFundManagement.Domain.csproj" />
|
||||
<Project Path="PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/Solution Items/">
|
||||
<File Path=".editorconfig" />
|
||||
<File Path=".gitignore" />
|
||||
@@ -9,10 +18,7 @@
|
||||
<File Path="PostFundManagement.snk" />
|
||||
<File Path="README.md" />
|
||||
</Folder>
|
||||
<Project Path="PostFundManagement.Api/PostFundManagement.Api.csproj" />
|
||||
<Project Path="PostFundManagement.Application/PostFundManagement.Application.csproj" Id="750c7754-53a7-4573-abed-5c436246a04d" />
|
||||
<Project Path="PostFundManagement.Domain/PostFundManagement.Domain.csproj" />
|
||||
<Project Path="PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj" />
|
||||
<Project Path="PostFundManagement.Jobs/PostFundManagement.Jobs.csproj" Id="81281806-b5ca-4784-87af-3e8feeac988c" />
|
||||
<Project Path="PostFundManagement.Tests/PostFundManagement.Tests.csproj" Id="ce650d27-8a68-436d-b5c1-db25f2286e85" />
|
||||
<Folder Name="/Tests/">
|
||||
<Project Path="PostFundManagement.Tests/PostFundManagement.Tests.csproj" Id="ce650d27-8a68-436d-b5c1-db25f2286e85" />
|
||||
</Folder>
|
||||
</Solution>
|
||||
|
||||
+52
-11
@@ -1,4 +1,55 @@
|
||||
services:
|
||||
pfm-scheduler:
|
||||
image: pfm-scheduler
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./PostFundManagement.Jobs/Dockerfile
|
||||
network: host
|
||||
container_name: pfm-scheduler
|
||||
environment:
|
||||
# Service layer caching feature flag
|
||||
- FeatureManagement__JobsWorker=${FEATURE_JOBS_WORKER:-true}}
|
||||
- FeatureManagement__EmailProcessorJobEnabled=${FEATURE_EMAIL_PROCESSOR_JOB_ENABLED:-true}}
|
||||
- FeatureManagement__ServiceCaching=${FEATURE_SERVICE_CACHING:-false}}
|
||||
|
||||
# Header forwarding overrides
|
||||
- DOTNET_ENVIRONMENT=${ENVIRONMENT:-Development}
|
||||
|
||||
# Postgres Database Overrides
|
||||
- ConnectionStrings__PfmDatabase=Server=${POSTGRES_HOST:-192.168.1.170};Port=${POSTGRES_PORT:-5432};Database=${POSTGRES_DB:-pfm};User Id=${POSTGRES_USER:-pfm-user};Password=${POSTGRES_PASSWORD:-};
|
||||
- ConnectionStrings__PfmSchedulerDatabase=Server=${POSTGRES_HOST:-192.168.1.170};Port=${POSTGRES_PORT:-5432};Database=pfm-scheduler;User Id=${POSTGRES_USER:-pfm-user};Password=${POSTGRES_PASSWORD:-};
|
||||
|
||||
# Garage S3 Settings
|
||||
- GeneralS3Settings__ServiceUrl=${GENERAL_S3_SERVICE_URL:-https://s3.garage.khongisa.co.za}
|
||||
- GeneralS3Settings__Region=${GENERAL_S3_REGION:-garage}
|
||||
- GeneralS3Settings__BucketName=${GENERAL_S3_BUCKET_NAME:-pfm}
|
||||
- GeneralS3Settings__CdnBaseUrl=${GENERAL_S3_CDN_BASE_URL:-https://pfm.cdn.khongisa.co.za}
|
||||
- GeneralS3Settings__AccessKey=${GENERAL_S3_ACCESS_KEY:-}
|
||||
- GeneralS3Settings__SecretKey=${GENERAL_S3_SECRET_KEY:-}
|
||||
|
||||
# HashIds overrides
|
||||
- HasherSettings__MinHashLength=${HASHER_MIN_HASH_LENGTH:-11}
|
||||
- HasherSettings__Salt=${HASHER_SALT:-}
|
||||
|
||||
# Data Protection Overrides
|
||||
- DataProtection__Certificate=${DATA_PROTECTION_CERTIFICATE:-}
|
||||
- DataProtection__Password=${DATA_PROTECTION_CERTIFICATE_PASSWORD:-}
|
||||
|
||||
# Monitoring Overrides
|
||||
- Monitoring__Address=${MONITORING_ADDRESS:-http://aspire-dashboard-service.aspire.svc.cluster.local:18889}
|
||||
- Monitoring__ServiceName=${MONITORING_SERVICE_NAME:-Pfm.DEV}
|
||||
- Monitoring__ApiKey=${MONITORING_API_KEY:-}
|
||||
|
||||
# Email Processor Overrides
|
||||
- Email__ProcessorJobCron=${EMAIL_PROCESSOR_CRON:-0 */5 * * * ?}
|
||||
- Email__Credentials__Password=${EMAIL_CREDENTIALS_PASSWORD:-}
|
||||
- Email__Credentials__Username=${EMAIL_CREDENTIALS_USERNAME:-}
|
||||
- Email__SmtpServer=${EMAIL_SMTP_SERVER:-}
|
||||
- Email__SmtpPort=${EMAIL_SMTP_PORT:-587}
|
||||
|
||||
# Redis overrides
|
||||
- ConnectionStrings__Redis=${REDIS_CONNECTION_STRING:-192.168.1.171:6379,ssl=false,abortConnect=false}
|
||||
restart: unless-stopped
|
||||
pfm-api:
|
||||
image: pfm-api
|
||||
build:
|
||||
@@ -8,10 +59,7 @@ services:
|
||||
container_name: pfm-api
|
||||
ports:
|
||||
- "8075:8080"
|
||||
environment:
|
||||
# Service layer caching feature flag
|
||||
- EnableServiceCaching=false
|
||||
|
||||
environment:
|
||||
# Header forwarding overrides
|
||||
- ASPNETCORE_ENVIRONMENT=${ENVIRONMENT:-Development}
|
||||
- ForwardedHeadersConfiguration__Enabled=true
|
||||
@@ -61,13 +109,6 @@ services:
|
||||
- Monitoring__Address=${MONITORING_ADDRESS:-http://aspire-dashboard-service.aspire.svc.cluster.local:18889}
|
||||
- Monitoring__ServiceName=${MONITORING_SERVICE_NAME:-Pfm.DEV}
|
||||
- Monitoring__ApiKey=${MONITORING_API_KEY:-}
|
||||
|
||||
# Email Processor Overrides
|
||||
- EmailProcessorCron=${EMAIL_PROCESSOR_CRON:-}
|
||||
- Email__Credentials__Password=${EMAIL_CREDENTIALS_PASSWORD:-}
|
||||
- Email__Credentials__Username=${EMAIL_CREDENTIALS_USERNAME:-}
|
||||
- Email__SmtpServer=${EMAIL_SMTP_SERVER:-}
|
||||
- Email__SmtpPort=${EMAIL_SMTP_PORT:-587}
|
||||
|
||||
# Redis overrides
|
||||
- ConnectionStrings__Redis=${REDIS_CONNECTION_STRING:-192.168.1.171:6379,ssl=false,abortConnect=false}
|
||||
|
||||
Reference in New Issue
Block a user