Implemented scheduling service and first two jobs
This commit is contained in:
@@ -1,21 +1,31 @@
|
||||
using PostFundManagement.Application.Events;
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
using PostFundManagement.Domain.Configuration.Email;
|
||||
|
||||
namespace PostFundManagement.Jobs;
|
||||
|
||||
public class JobsWorker(IJobOrchestrator jobOrchestrator, IFeatureManager featureManager,
|
||||
ILogger<JobsWorker> logger) : BackgroundService
|
||||
public class JobsWorker(IJobOrchestrator jobOrchestrator, IFeatureManager featureManager,
|
||||
ILogger<JobsWorker> logger, IOptions<SmtpSettings> emailOptions) : BackgroundService
|
||||
{
|
||||
readonly SmtpSettings emailSettings = emailOptions.Value;
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
if(!await featureManager.IsEnabledAsync(nameof(JobsWorker)))
|
||||
if (!await featureManager.IsEnabledAsync(nameof(JobsWorker)))
|
||||
{
|
||||
logger.LogInformation("JobsWorker is disabled.");
|
||||
logger.LogInformation("Recurring job automatic registration disabled.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: scheduler reccuring jobs
|
||||
if (await featureManager.IsEnabledAsync(FeatureEmailProcessor))
|
||||
await jobOrchestrator.ScheduleAsync(ProcessEmailEvent.Create(), "0 */5 * * * ?", stoppingToken);
|
||||
|
||||
logger.LogInformation("JobsWorker is stopping.");
|
||||
if (await featureManager.IsEnabledAsync(FeatureLateProjectReminder))
|
||||
await jobOrchestrator.ScheduleAsync(LateProjectEvent.Create(), "", stoppingToken);
|
||||
|
||||
// TODO: Add job to check for non-compliant projects once a week
|
||||
|
||||
logger.LogInformation("Recurring jobs have been registered or updated.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
"FeatureManagement": {
|
||||
"JobsWorker": true,
|
||||
"EmailProcessorJobEnabled": true,
|
||||
"LateProjectReminderEnabled": true,
|
||||
"ServiceCaching": false
|
||||
},
|
||||
"GeneralS3Settings": {
|
||||
@@ -28,7 +29,6 @@
|
||||
}
|
||||
},
|
||||
"Email": {
|
||||
"ProcessorJobCron": "0 */5 * * * ?",
|
||||
"SmtpServer": "smtp.example.com",
|
||||
"SmtpPort": 587,
|
||||
"SenderEmail": "noreply@example.com",
|
||||
|
||||
Reference in New Issue
Block a user