EasyCronJob
EasyCronJob copied to clipboard
Don't attempt to configure a job if the expression is null.
If you use the AutoConfigure extension method:
public void ConfigureServices(IServiceCollection services)
{
...
services.InitializeCronServices();
services.AutoConfigurer();
}
And decide you want to "disable a job and comment out the configuration:
//"CronJobs": {
// "CronJob1": {
// "CronExpression": "*/1 * * * *"
// }
Currently you'll get an exception with the call to AutoConfigurer:
In your job, the constructor will throw:
public CronJob1(ILogger<CronJob1> logger, ICronConfiguration<CronJob1> cronConfiguration) : base(cronConfiguration.CronExpression, cronConfiguration.TimeZoneInfo, cronConfiguration.CronFormat)
{
...
}
The base(cronConfiguration.CronExpression
will throw because it tries to pass null into Chronos.
This change will ignore and not create an instance of the job class if the expression is not defined.