ServiceRunner.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Quartz;
  2. using Quartz.Impl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Topshelf;
  9. using XYY.Tool.TimingTask.jobs;
  10. namespace XYY.Tool.QuotaReduction
  11. {
  12. public class ServiceRunner : ServiceControl, ServiceSuspend
  13. {
  14. private readonly IScheduler scheduler;
  15. public ServiceRunner()
  16. {
  17. scheduler = StdSchedulerFactory.GetDefaultScheduler().Result;
  18. }
  19. public bool Start(HostControl hostControl)
  20. {
  21. scheduler.Start();
  22. //PBPostManifestJob testPbJob = new PBPostManifestJob();
  23. //testPbJob.Execute(null).Wait();
  24. //具体任务启动可在配置文件编写
  25. for (var i = 0; i < JobConfig.jobs.Length; i++)
  26. {
  27. IJobDetail job1 = JobConfig.jobs[i];
  28. ITrigger trigger1 = TriggerBuilder.Create().StartNow().WithCronSchedule(JobConfig.crons[i]).Build();
  29. scheduler.ScheduleJob(job1, trigger1);
  30. }
  31. return true;
  32. }
  33. public bool Continue(HostControl hostControl)
  34. {
  35. scheduler.ResumeAll();
  36. return true;
  37. }
  38. public bool Pause(HostControl hostControl)
  39. {
  40. scheduler.PauseAll();
  41. return true;
  42. }
  43. public bool Stop(HostControl hostControl)
  44. {
  45. scheduler.Shutdown(false);
  46. return true;
  47. }
  48. }
  49. }