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
+23 -11
View File
@@ -3,6 +3,7 @@ using CMSMicroservice.Infrastructure.Data.Seeding;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.WebApi.Hubs;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Hosting;
@@ -208,17 +209,28 @@ using (var scope = app.Services.CreateScope())
{
var recurringJobManager = scope.ServiceProvider.GetRequiredService<IRecurringJobManager>();
// Weekly Commission Calculation: Every Sunday at 00:05 (UTC)
recurringJobManager.AddOrUpdate<CMSMicroservice.Infrastructure.BackgroundJobs.WeeklyCommissionJob>(
recurringJobId: "weekly-commission-calculation",
methodCall: job => job.ExecuteAsync(null, CancellationToken.None),
cronExpression: "5 0 * * 0", // Sunday at 00:05
options: new RecurringJobOptions
{
TimeZone = TimeZoneInfo.Utc
});
// Weekly Commission Calculation: Every Sunday at 00:05 (configurable)
var weeklyCommissionEnabled = app.Configuration.GetValue<bool>("BackgroundJobs:WeeklyCommissionCalculation:Enabled", true);
var weeklyCommissionCron = app.Configuration.GetValue<string>("BackgroundJobs:WeeklyCommissionCalculation:CronExpression", "5 0 * * 0");
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
CMSMicroservice.WebApi.Workers.DayaLoanCheckWorker.Schedule(recurringJobManager);
@@ -229,7 +241,7 @@ using (var scope = app.Services.CreateScope())
recurringJobId: "chatika-account-activation",
methodCall: job => job.ExecuteAsync(CancellationToken.None),
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)");
}