using System.Diagnostics; using System.Reflection; using System.Xml; using Common; using Common.Singleton; using Database.Database; using CMS.Worker; using Microsoft.EntityFrameworkCore; using MyKungKangWorker; using MyKungKangWorker.Utils; using Quartz; XmlDocument log4netConfig = new XmlDocument(); log4netConfig.Load(File.OpenRead("log4net.config")); var repo = log4net.LogManager.CreateRepository( Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy) ); log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]); var log = log4net.LogManager.GetLogger(typeof(Program)); IHost host = Host.CreateDefaultBuilder(args) .ConfigureServices(services => { services.AddDbContext(ServiceLifetime.Transient); //services.AddQuartz(q => //{ // // q.UseMicrosoftDependencyInjectionScopedJobFactory(); // var jobKey = new JobKey("WeeklyPrizeScheduler"); // q.AddJob(opts => opts.WithIdentity(jobKey)); // q.AddTrigger( // opts => // opts.ForJob(jobKey) // .WithIdentity("WeeklyPrizeScheduler-trigger") // // .WithCronSchedule("10 10 0 * * ?") // start at 0h10p every day // .WithSimpleSchedule(x => x.WithIntervalInMinutes(10).RepeatForever()) // ); // start at every hour // services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); //}); // services.AddQuartz(q => // { // // q.UseMicrosoftDependencyInjectionScopedJobFactory(); // var jobKey = new JobKey("MonthlyPrizeScheduler"); // q.AddJob(opts => opts.WithIdentity(jobKey)); // q.AddTrigger( // opts => // opts.ForJob(jobKey) // .WithIdentity("MonthlyPrizeScheduler-trigger") // .WithCronSchedule("10 10 0 * * ?") // start at 0h10p every day // ); // start at every hour // services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); // }); services.AddQuartz(q => { // q.UseMicrosoftDependencyInjectionScopedJobFactory(); var jobKey = new JobKey("ReportByHourJob"); q.AddJob(opts => opts.WithIdentity(jobKey)); q.AddTrigger( opts => opts.ForJob(jobKey) .WithIdentity("ReportByHourJob-trigger") .WithCronSchedule("0 1 * * * ?") ); // start at every hour services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); }); services.AddQuartz(q => { // q.UseMicrosoftDependencyInjectionScopedJobFactory(); var jobKey = new JobKey("ReportByDayJob"); q.AddJob(opts => opts.WithIdentity(jobKey)); q.AddTrigger( opts => opts.ForJob(jobKey) .WithIdentity("ReportByDayJob-trigger") .WithCronSchedule("0 1 0 * * ?") ); // start at 0AM every day services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); }); // services.AddQuartz(q => // { // // q.UseMicrosoftDependencyInjectionScopedJobFactory(); // var jobKey = new JobKey("ReportByMonthJob"); // q.AddJob(opts => opts.WithIdentity(jobKey)); // q.AddTrigger( // opts => // opts.ForJob(jobKey) // .WithIdentity("ReportByMonthJob-trigger") // .WithCronSchedule("0 0 0 * * ?") // ); // start at 0AM every day // // .WithCronSchedule("0 45 * * * ?")); // start at 0AM every day // services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); // }); }) .Build(); host.Run();