|
| 1 | +using System.Collections.Specialized; |
| 2 | +using System.Linq; |
| 3 | +using Quartz; |
| 4 | +using Quartz.Impl; |
| 5 | + |
| 6 | +namespace InEngine.Core.Scheduling |
| 7 | +{ |
| 8 | + public class SuperScheduler |
| 9 | + { |
| 10 | + public Schedule Schedule { get; set; } |
| 11 | + public IScheduler Scheduler { get; set; } |
| 12 | + public string SchedulerInstanceName { get; set; } = "InEngine"; |
| 13 | + public string SchedulerThreadPoolType { get; set; } = "Quartz.Simpl.SimpleThreadPool, Quartz"; |
| 14 | + public string SchedulerThreadCount { get; set; } = "20"; |
| 15 | + public string SchedulerThreadPriority { get; set; } = "Normal"; |
| 16 | + |
| 17 | + public void Initialize() |
| 18 | + { |
| 19 | + Scheduler = new StdSchedulerFactory(new NameValueCollection { |
| 20 | + ["quartz.scheduler.instanceName"] = SchedulerInstanceName, |
| 21 | + ["quartz.threadPool.type"] = SchedulerThreadPoolType, |
| 22 | + ["quartz.threadPool.threadCount"] = SchedulerThreadCount, |
| 23 | + ["quartz.threadPool.threadPriority"] = SchedulerThreadPriority |
| 24 | + }).GetScheduler(); |
| 25 | + |
| 26 | + Schedule = new Schedule(); |
| 27 | + PluginAssembly.Load<IPlugin>().ForEach(x => { |
| 28 | + x.Plugins.ForEach(y => y.Schedule(Schedule)); |
| 29 | + }); |
| 30 | + |
| 31 | + Schedule.JobGroups.AsEnumerable().ToList().ForEach(x => { |
| 32 | + x.Value.Registrations.AsEnumerable().ToList().ForEach(y => { |
| 33 | + Scheduler.ScheduleJob(y.Value.JobDetail, y.Value.Trigger); |
| 34 | + }); |
| 35 | + }); |
| 36 | + } |
| 37 | + |
| 38 | + public void Start() |
| 39 | + { |
| 40 | + Scheduler.Start(); |
| 41 | + } |
| 42 | + |
| 43 | + public void Shutdown() |
| 44 | + { |
| 45 | + if (Scheduler.IsStarted) |
| 46 | + Scheduler.Shutdown(); |
| 47 | + } |
| 48 | + |
| 49 | + public JobBuilder MakeJobBuilder(AbstractCommand command) |
| 50 | + { |
| 51 | + return JobBuilder.Create(command.GetType()) |
| 52 | + .WithIdentity($"{command.Name}:job:{command.ScheduleId}", command.SchedulerGroup); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments