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)
|
IConfiguration configuration)
|
||||||
where TJob : IJob
|
where TJob : IJob
|
||||||
{
|
{
|
||||||
var expression = configuration[$"{nameof(TJob)}:CronExpression"];
|
var expression = configuration[$"{typeof(TJob).Name}:CronExpression"];
|
||||||
if (string.IsNullOrWhiteSpace(expression))
|
if (string.IsNullOrWhiteSpace(expression))
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
"Cron expression for the Worker job is not configured. " +
|
"Cron expression for the Worker job is not configured. " +
|
||||||
"Please provide a valid cron schedule in the configuration under " +
|
"Please provide a valid cron schedule in the configuration under " +
|
||||||
$"'{nameof(TJob)}:CronExpression'.");
|
$"'{typeof(TJob).FullName}:CronExpression'.");
|
||||||
|
|
||||||
return q.ScheduleJobDefault<TJob>(expression);
|
return q.ScheduleJobDefault<TJob>(expression);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,11 +2,11 @@ using Quartz;
|
|||||||
|
|
||||||
namespace EnvelopeGenerator.Finalizer.Job
|
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;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
using CommandDotNet.Execution;
|
using CommandDotNet.Execution;
|
||||||
using EnvelopeGenerator.Application.ThirdPartyModules.Queries;
|
using EnvelopeGenerator.Application.ThirdPartyModules.Queries;
|
||||||
using EnvelopeGenerator.DependencyInjection;
|
using EnvelopeGenerator.DependencyInjection;
|
||||||
|
using EnvelopeGenerator.Finalizer;
|
||||||
using EnvelopeGenerator.Finalizer.Job;
|
using EnvelopeGenerator.Finalizer.Job;
|
||||||
using EnvelopeGenerator.Finalizer.Models;
|
using EnvelopeGenerator.Finalizer.Models;
|
||||||
using EnvelopeGenerator.Infrastructure;
|
using EnvelopeGenerator.Infrastructure;
|
||||||
@ -49,21 +50,8 @@ try
|
|||||||
#region Quartz
|
#region Quartz
|
||||||
builder.Services.AddQuartz(q =>
|
builder.Services.AddQuartz(q =>
|
||||||
{
|
{
|
||||||
var name = $"{typeof(FinishEnvelopeJob).FullName}";
|
q.ScheduleJobDefault<FinishEnvelopeJob>(config);
|
||||||
var jobKey = new JobKey(name);
|
q.ScheduleJobDefault<EnvelopeTaskApiJob>(config);
|
||||||
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));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddQuartzServer(options =>
|
builder.Services.AddQuartzServer(options =>
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"FinishEnvelopeJob": {
|
"FinishEnvelopeJob": {
|
||||||
"CronExpression": "* * * * * ?"
|
"CronExpression": "* * * * * ?"
|
||||||
|
},
|
||||||
|
"EnvelopeTaskApiJob": {
|
||||||
|
"CronExpression": "* * * * * ?"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user