/// <summary> /// 创建定时作业 /// </summary> /// <param name="schedule"></param> /// <returns></returns> private static IJobDetail CreateJob(JobSchedule schedule) { return(JobBuilder .Create(schedule.JobType) .WithIdentity(GenerateIdentity(schedule, IdentityType.Job)) .WithDescription(schedule.CronExpression) .Build()); }
/// <summary> /// 创建触发器 /// </summary> /// <param name="schedule"></param> /// <returns></returns> private static ITrigger CreateTrigger(JobSchedule schedule) { return(TriggerBuilder .Create() .WithIdentity(GenerateIdentity(schedule, IdentityType.Trigger)) .WithCronSchedule(schedule.CronExpression) .WithDescription(schedule.JobType.FullName) .Build()); }
/// <summary> /// 生成一个标识(类似主键的意思) /// </summary> /// <param name="schedule"></param> /// <param name="identityType">标识类型,一个job作业,或者是trigger触发器</param> /// <returns></returns> private static string GenerateIdentity(JobSchedule schedule, IdentityType identityType) { switch (identityType) { case IdentityType.Job: return($"NdcPayInternal_Job_{schedule.JobType.Name}"); case IdentityType.Trigger: return($"NdcPayInternal_Trigger_{schedule.JobType.Name}"); } return(schedule.JobType.FullName); }