feat: add background job configuration for weekly commission calculation - Updated appsettings and Program.cs to enable configurable scheduling for weekly commission jobs
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 2m9s

This commit is contained in:
masoodafar-web
2025-12-27 01:37:43 +03:30
parent 322242fbab
commit cd2549775a
5 changed files with 112 additions and 17 deletions
+5
View File
@@ -492,3 +492,8 @@ fabric.properties
.idea/caches/build_file_checksums.ser .idea/caches/build_file_checksums.ser
/src/.idea /src/.idea
# Environment-specific configuration files with sensitive data
**/appsettings.Staging.json
**/appsettings.Production.json
**/appsettings.*.local.json
@@ -7,6 +7,10 @@
<DockerfileContext>..\..\..</DockerfileContext> <DockerfileContext>..\..\..</DockerfileContext>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Update="appsettings.*.json" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.23.3" /> <PackageReference Include="Google.Protobuf" Version="3.23.3" />
<PackageReference Include="Grpc.AspNetCore" Version="2.54.0" /> <PackageReference Include="Grpc.AspNetCore" Version="2.54.0" />
+23 -11
View File
@@ -3,6 +3,7 @@ using CMSMicroservice.Infrastructure.Data.Seeding;
using CMSMicroservice.Application.Common.Interfaces; using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.WebApi.Hubs; using CMSMicroservice.WebApi.Hubs;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
@@ -208,17 +209,28 @@ using (var scope = app.Services.CreateScope())
{ {
var recurringJobManager = scope.ServiceProvider.GetRequiredService<IRecurringJobManager>(); var recurringJobManager = scope.ServiceProvider.GetRequiredService<IRecurringJobManager>();
// Weekly Commission Calculation: Every Sunday at 00:05 (UTC) // Weekly Commission Calculation: Every Sunday at 00:05 (configurable)
recurringJobManager.AddOrUpdate<CMSMicroservice.Infrastructure.BackgroundJobs.WeeklyCommissionJob>( var weeklyCommissionEnabled = app.Configuration.GetValue<bool>("BackgroundJobs:WeeklyCommissionCalculation:Enabled", true);
recurringJobId: "weekly-commission-calculation", var weeklyCommissionCron = app.Configuration.GetValue<string>("BackgroundJobs:WeeklyCommissionCalculation:CronExpression", "5 0 * * 0");
methodCall: job => job.ExecuteAsync(null, CancellationToken.None),
cronExpression: "5 0 * * 0", // Sunday at 00:05
options: new RecurringJobOptions
{
TimeZone = TimeZoneInfo.Utc
});
app.Logger.LogInformation("✅ Hangfire recurring job 'weekly-commission-calculation' registered (Cron: 5 0 * * 0 - Sunday 00:05 UTC)"); if (weeklyCommissionEnabled)
{
recurringJobManager.AddOrUpdate<CMSMicroservice.Infrastructure.BackgroundJobs.WeeklyCommissionJob>(
recurringJobId: "weekly-commission-calculation",
methodCall: job => job.ExecuteAsync(null, CancellationToken.None),
cronExpression: weeklyCommissionCron,
options: new RecurringJobOptions
{
TimeZone = TimeZoneInfo.Local
});
app.Logger.LogInformation("✅ Hangfire recurring job 'weekly-commission-calculation' registered (Cron: {Cron})", weeklyCommissionCron);
}
else
{
recurringJobManager.RemoveIfExists("weekly-commission-calculation");
app.Logger.LogInformation("⚠️ Hangfire recurring job 'weekly-commission-calculation' is DISABLED in configuration");
}
// Daya Loan Check: Every 15 minutes // Daya Loan Check: Every 15 minutes
CMSMicroservice.WebApi.Workers.DayaLoanCheckWorker.Schedule(recurringJobManager); CMSMicroservice.WebApi.Workers.DayaLoanCheckWorker.Schedule(recurringJobManager);
@@ -229,7 +241,7 @@ using (var scope = app.Services.CreateScope())
recurringJobId: "chatika-account-activation", recurringJobId: "chatika-account-activation",
methodCall: job => job.ExecuteAsync(CancellationToken.None), methodCall: job => job.ExecuteAsync(CancellationToken.None),
cronExpression: "*/5 * * * *", cronExpression: "*/5 * * * *",
options: new RecurringJobOptions { TimeZone = TimeZoneInfo.Utc }); options: new RecurringJobOptions { TimeZone = TimeZoneInfo.Local });
app.Logger.LogInformation("✅ Hangfire recurring job 'chatika-account-activation' registered (Cron: */5 * * * * - Every 5 minutes)"); app.Logger.LogInformation("✅ Hangfire recurring job 'chatika-account-activation' registered (Cron: */5 * * * * - Every 5 minutes)");
} }
@@ -1,10 +1,78 @@
{ {
"Logging": { "UseRealPaymentGateway": false,
"LogLevel": { "JwtSecurityKey": "TvlZVx5TJaHs8e9HgUdGzhGP2CIidoI444nAj+8+g7c=",
"Default": "Debug", "JwtIssuer": "https://localhost",
"System": "Information", "JwtAudience": "https://localhost",
"Grpc": "Information", "JwtExpiryInDays": 5,
"Microsoft": "Information" "ConnectionStrings": {
"DefaultConnection": "Data Source=194.5.195.53,31433; Initial Catalog=Foursat;User ID=sa;Password=87zH26nbqT;Connection Timeout=300000;MultipleActiveResultSets=True;Encrypt=False",
"providerName": "System.Data.SqlClient"
},
"Otp": {
"Secret": "K2w8k1h1mH2Qz1kqWk0c8kQ2Pq8q9H1eE2nqN1qQ8x7M="
},
"Monitoring": {
"SentryEnabled": false,
"SentryDsn": "",
"SlackEnabled": false,
"SlackWebhookUrl": "",
"EmailAlertsEnabled": false,
"AdminEmails": [
"admin@example.com"
],
"SmsNotificationsEnabled": false,
"SmsApiKey": "",
"SmsGatewayUrl": ""
},
"Email": {
"Enabled": true,
"SmtpHost": "smtp.gmail.com",
"SmtpPort": 587,
"SmtpUsername": "your-email@gmail.com",
"SmtpPassword": "your-app-password",
"FromEmail": "noreply@foursat.com",
"FromName": "FourSat CMS",
"EnableSsl": true
},
"Sms": {
"Enabled": true,
"Provider": "Kavenegar",
"KavenegarApiKey": "497263626F32626A48685A6137524C4F78575A766E4C74694A556B79317648424964655030682B554545413D",
"Sender": "1000001110100"
},
"DayaPayment": {
"BaseUrl": "https://api.daya.ir",
"ApiKey": "YOUR_DAYA_API_KEY"
},
"DayaApi": {
"UseMock": false,
"BaseAddress": "https://Dayadiamond.ir",
"MerchantPermissionKey": "56146364$04sXjethI5WxhItR1Q9xnmFdJzl2BB8Bclsq8dAy7YVSZp3vtt-wP7ivrcCvmKLq",
"CacheDurationMinutes": 20
},
"Chatika": {
"Enabled": true,
"BaseUrl": "https://api.chatika.ir",
"ApiKey": "tIukvL8dnV4cB3yVWcCD9Xyfbj8rBxm5wPt2mLyJCgTsBBoMTWjt6mFEqQwpw-er"
},
"BackgroundJobs": {
"WeeklyCommissionCalculation": {
"Enabled": true,
"CronExpression": "5 0 * * 0"
} }
},
"AllowedHosts": "*",
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2"
}
},
"Authentication": {
"Authority": "https://ids.domain.com/",
"Audience": "domain_api"
},
"Seq": {
"ServerUrl": "https://seq.afrino.co",
"ApiKey": "oxpvpUzU1pZxMS4s3Fqq"
} }
} }
@@ -55,6 +55,12 @@
"BaseUrl": "https://api.chatika.ir", "BaseUrl": "https://api.chatika.ir",
"ApiKey": "tIukvL8dnV4cB3yVWcCD9Xyfbj8rBxm5wPt2mLyJCgTsBBoMTWjt6mFEqQwpw-er" "ApiKey": "tIukvL8dnV4cB3yVWcCD9Xyfbj8rBxm5wPt2mLyJCgTsBBoMTWjt6mFEqQwpw-er"
}, },
"BackgroundJobs": {
"WeeklyCommissionCalculation": {
"Enabled": true,
"CronExpression": "5 0 * * 0"
}
},
"AllowedHosts": "*", "AllowedHosts": "*",
"Kestrel": { "Kestrel": {
"EndpointDefaults": { "EndpointDefaults": {