Exemplo n.º 1
0
        private RecurringJobInfo Convert(RecurringJobJsonOptions option)
        {
            ValidateJsonOptions(option);

            return(new RecurringJobInfo
            {
                RecurringJobId = option.JobName,
                Method = option.JobType.GetTypeInfo().GetDeclaredMethod(nameof(IRecurringJob.Execute)),
                Cron = option.Cron,
                Queue = option.Queue ?? EnqueuedState.DefaultQueue,
                TimeZone = option.TimeZone ?? TimeZoneInfo.Utc,
                JobData = option.JobData,
                Enable = option.Enable ?? true
            });
        }
Exemplo n.º 2
0
        private void ValidateJsonOptions(RecurringJobJsonOptions option)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option));
            }

            if (string.IsNullOrWhiteSpace(option.JobName))
            {
                throw new Exception($"The json token 'job-name' is null, empty, or consists only of white-space.");
            }

            if (!option.JobType.GetTypeInfo().ImplementedInterfaces.Contains(typeof(IRecurringJob)))
            {
                throw new Exception($"job-type: {option.JobType} must impl the interface {typeof(IRecurringJob)}.");
            }
        }