Program.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.Diagnostics;
  2. using System.Reflection;
  3. using System.Xml;
  4. using Common;
  5. using Common.Singleton;
  6. using Database.Database;
  7. using CMS.Worker;
  8. using Microsoft.EntityFrameworkCore;
  9. using MyKungKangWorker;
  10. using MyKungKangWorker.Utils;
  11. using Quartz;
  12. XmlDocument log4netConfig = new XmlDocument();
  13. log4netConfig.Load(File.OpenRead("log4net.config"));
  14. var repo = log4net.LogManager.CreateRepository(
  15. Assembly.GetEntryAssembly(),
  16. typeof(log4net.Repository.Hierarchy.Hierarchy)
  17. );
  18. log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
  19. var log = log4net.LogManager.GetLogger(typeof(Program));
  20. IHost host = Host.CreateDefaultBuilder(args)
  21. .ConfigureServices(services =>
  22. {
  23. services.AddDbContext<DbContext>(ServiceLifetime.Transient);
  24. //services.AddQuartz(q =>
  25. //{
  26. // // q.UseMicrosoftDependencyInjectionScopedJobFactory();
  27. // var jobKey = new JobKey("WeeklyPrizeScheduler");
  28. // q.AddJob<WeeklyPrizeScheduler>(opts => opts.WithIdentity(jobKey));
  29. // q.AddTrigger(
  30. // opts =>
  31. // opts.ForJob(jobKey)
  32. // .WithIdentity("WeeklyPrizeScheduler-trigger")
  33. // // .WithCronSchedule("10 10 0 * * ?") // start at 0h10p every day
  34. // .WithSimpleSchedule(x => x.WithIntervalInMinutes(10).RepeatForever())
  35. // ); // start at every hour
  36. // services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
  37. //});
  38. // services.AddQuartz(q =>
  39. // {
  40. // // q.UseMicrosoftDependencyInjectionScopedJobFactory();
  41. // var jobKey = new JobKey("MonthlyPrizeScheduler");
  42. // q.AddJob<MonthlyPrizeScheduler>(opts => opts.WithIdentity(jobKey));
  43. // q.AddTrigger(
  44. // opts =>
  45. // opts.ForJob(jobKey)
  46. // .WithIdentity("MonthlyPrizeScheduler-trigger")
  47. // .WithCronSchedule("10 10 0 * * ?") // start at 0h10p every day
  48. // ); // start at every hour
  49. // services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
  50. // });
  51. services.AddQuartz(q =>
  52. {
  53. // q.UseMicrosoftDependencyInjectionScopedJobFactory();
  54. var jobKey = new JobKey("ReportByHourJob");
  55. q.AddJob<ReportByHourScheduler>(opts => opts.WithIdentity(jobKey));
  56. q.AddTrigger(
  57. opts =>
  58. opts.ForJob(jobKey)
  59. .WithIdentity("ReportByHourJob-trigger")
  60. .WithCronSchedule("0 1 * * * ?")
  61. ); // start at every hour
  62. services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
  63. });
  64. services.AddQuartz(q =>
  65. {
  66. // q.UseMicrosoftDependencyInjectionScopedJobFactory();
  67. var jobKey = new JobKey("ReportByDayJob");
  68. q.AddJob<ReportByDayScheduler>(opts => opts.WithIdentity(jobKey));
  69. q.AddTrigger(
  70. opts =>
  71. opts.ForJob(jobKey)
  72. .WithIdentity("ReportByDayJob-trigger")
  73. .WithCronSchedule("0 1 0 * * ?")
  74. ); // start at 0AM every day
  75. services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
  76. });
  77. // services.AddQuartz(q =>
  78. // {
  79. // // q.UseMicrosoftDependencyInjectionScopedJobFactory();
  80. // var jobKey = new JobKey("ReportByMonthJob");
  81. // q.AddJob<ReportByMonthScheduler>(opts => opts.WithIdentity(jobKey));
  82. // q.AddTrigger(
  83. // opts =>
  84. // opts.ForJob(jobKey)
  85. // .WithIdentity("ReportByMonthJob-trigger")
  86. // .WithCronSchedule("0 0 0 * * ?")
  87. // ); // start at 0AM every day
  88. // // .WithCronSchedule("0 45 * * * ?")); // start at 0AM every day
  89. // services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
  90. // });
  91. })
  92. .Build();
  93. host.Run();