up
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using StellaOps.DependencyInjection.Validation;
|
||||
|
||||
namespace StellaOps.Plugin.MyJob;
|
||||
|
||||
/// <summary>
|
||||
/// Validates <see cref="MyJobOptions"/> configuration.
|
||||
/// </summary>
|
||||
public sealed class MyJobOptionsValidator : OptionsValidatorBase<MyJobOptions>
|
||||
{
|
||||
protected override string SectionPrefix => MyJobOptions.SectionName;
|
||||
|
||||
protected override void ValidateOptions(MyJobOptions options, ValidationContext context)
|
||||
{
|
||||
context
|
||||
.RequireNotEmpty(options.CronSchedule, nameof(options.CronSchedule))
|
||||
.RequirePositive(options.MaxExecutionMinutes, nameof(options.MaxExecutionMinutes))
|
||||
.RequirePositive(options.BatchSize, nameof(options.BatchSize))
|
||||
.RequireInRange(options.MaxExecutionMinutes, nameof(options.MaxExecutionMinutes), 1, 1440)
|
||||
.RequireInRange(options.BatchSize, nameof(options.BatchSize), 1, 10000);
|
||||
|
||||
// Validate cron expression format (basic check)
|
||||
if (!string.IsNullOrWhiteSpace(options.CronSchedule))
|
||||
{
|
||||
var parts = options.CronSchedule.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length < 5 || parts.Length > 6)
|
||||
{
|
||||
context.AddError(nameof(options.CronSchedule), "must be a valid cron expression with 5 or 6 fields.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user