| | |
| | | |
| | | namespace WIDESEA_Core.QuartzJob |
| | | { |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡è°åº¦ å¯å¨æå¡ |
| | | /// </summary> |
| | | public static class JobSetup |
| | | { |
| | | public static void AddJobSetup(this IServiceCollection services) |
| | | public static void AddJobSetup(this IServiceCollection services, Action<IServiceCollection> configureJobs = null) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | |
| | | services.AddSingleton<IJobFactory, JobFactory>(); |
| | | //å°SchedulerCenterServer注å
¥å°æå¡ä¸ |
| | | services.AddSingleton<ISchedulerCenter, SchedulerCenterServer>(); |
| | | |
| | | //任塿³¨å
¥ |
| | | var baseType = typeof(IJob); |
| | | //è·åå½ååºç¨ç¨åºåçç¸å¯¹æç´¢è·¯å¾ |
| | |
| | | { |
| | | services.AddTransient(implementType); |
| | | } |
| | | |
| | | // æ·»å 宿¶å¯å¨é
ç½® |
| | | services.AddTransient<StartupJob>(); |
| | | services.AddSingleton(new JobSchedule( |
| | | jobType: typeof(StartupJob), |
| | | cronExpression: "0 0 8 ? * *")); // æ¯å¤©ä¸å8ç¹æ§è¡ |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¯å¨ä»»å¡ |
| | | /// </summary> |
| | | public class StartupJob : IJob |
| | | { |
| | | private readonly ISchedulerCenter _schedulerCenter; |
| | | |
| | | public StartupJob(ISchedulerCenter schedulerCenter) |
| | | { |
| | | _schedulerCenter = schedulerCenter; |
| | | } |
| | | |
| | | public async Task Execute(IJobExecutionContext context) |
| | | { |
| | | // å¨è¿éå¯å¨ææéè¦å®æ¶æ§è¡çä»»å¡ |
| | | await _schedulerCenter.StartScheduleAsync(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡è°åº¦é
ç½® |
| | | /// </summary> |
| | | public class JobSchedule |
| | | { |
| | | public Type JobType { get; } |
| | | public string CronExpression { get; } |
| | | |
| | | public JobSchedule(Type jobType, string cronExpression) |
| | | { |
| | | JobType = jobType; |
| | | CronExpression = cronExpression; |
| | | } |
| | | } |
| | | } |