refactor(Program): simplify Quartz job registration and add EnvelopeTaskApiJob
- Replaced manual FinishEnvelopeJob Quartz setup with ScheduleJobDefault extension - Added scheduling for EnvelopeTaskApiJob - Updated using directives to include EnvelopeGenerator.Finalizer namespace - Improved maintainability by removing redundant Quartz configuration logic
This commit is contained in:
parent
695d7c83e0
commit
1713a65014
@ -23,12 +23,12 @@ public static class Extensions
|
||||
IConfiguration configuration)
|
||||
where TJob : IJob
|
||||
{
|
||||
var expression = configuration[$"{nameof(TJob)}:CronExpression"];
|
||||
var expression = configuration[$"{typeof(TJob).Name}:CronExpression"];
|
||||
if (string.IsNullOrWhiteSpace(expression))
|
||||
throw new InvalidOperationException(
|
||||
"Cron expression for the Worker job is not configured. " +
|
||||
"Please provide a valid cron schedule in the configuration under " +
|
||||
$"'{nameof(TJob)}:CronExpression'.");
|
||||
$"'{typeof(TJob).FullName}:CronExpression'.");
|
||||
|
||||
return q.ScheduleJobDefault<TJob>(expression);
|
||||
}
|
||||
|
||||
@ -2,11 +2,11 @@ using Quartz;
|
||||
|
||||
namespace EnvelopeGenerator.Finalizer.Job
|
||||
{
|
||||
public class EnvelopeTaskApi : IJob
|
||||
public class EnvelopeTaskApiJob : IJob
|
||||
{
|
||||
private readonly ILogger<EnvelopeTaskApi> _logger;
|
||||
private readonly ILogger<EnvelopeTaskApiJob> _logger;
|
||||
|
||||
public EnvelopeTaskApi(ILogger<EnvelopeTaskApi> logger)
|
||||
public EnvelopeTaskApiJob(ILogger<EnvelopeTaskApiJob> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
using CommandDotNet.Execution;
|
||||
using EnvelopeGenerator.Application.ThirdPartyModules.Queries;
|
||||
using EnvelopeGenerator.DependencyInjection;
|
||||
using EnvelopeGenerator.Finalizer;
|
||||
using EnvelopeGenerator.Finalizer.Job;
|
||||
using EnvelopeGenerator.Finalizer.Models;
|
||||
using EnvelopeGenerator.Infrastructure;
|
||||
@ -49,21 +50,8 @@ try
|
||||
#region Quartz
|
||||
builder.Services.AddQuartz(q =>
|
||||
{
|
||||
var name = $"{typeof(FinishEnvelopeJob).FullName}";
|
||||
var jobKey = new JobKey(name);
|
||||
q.AddJob<FinishEnvelopeJob>(opts => opts.WithIdentity(jobKey));
|
||||
|
||||
var expression = config[nameof(FinishEnvelopeJob) + ":CronExpression"];
|
||||
if (string.IsNullOrWhiteSpace(expression))
|
||||
throw new InvalidOperationException(
|
||||
"Cron expression for the Worker job is not configured. " +
|
||||
"Please provide a valid cron schedule in the configuration under " +
|
||||
$"'{nameof(FinishEnvelopeJob)}:CronExpression'.");
|
||||
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(jobKey)
|
||||
.WithIdentity(name + "-trigger")
|
||||
.WithCronSchedule(expression));
|
||||
q.ScheduleJobDefault<FinishEnvelopeJob>(config);
|
||||
q.ScheduleJobDefault<EnvelopeTaskApiJob>(config);
|
||||
});
|
||||
|
||||
builder.Services.AddQuartzServer(options =>
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
{
|
||||
"FinishEnvelopeJob": {
|
||||
"CronExpression": "* * * * * ?"
|
||||
},
|
||||
"EnvelopeTaskApiJob": {
|
||||
"CronExpression": "* * * * * ?"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user