static void Main(string[] args) { var host = new HostBuilder() .ConfigureAppConfiguration(c => { c.AddJsonFile("appsettings.json", optional: true); }) .ConfigureServices(s => { s.AddQuartz(o => { o.WaitForJobsToComplete = true; //o.UseSqlite(connectString: "Data Source=db.3db", ensureDatabaseIsCreated: false); }) .AddJob <MyJob>() //.AddJob<MyJobWithContext>(); .AddJob <MyJobNoConfigFromFile>(o => { //o.Identity = "MyJobInLine"; o.CronSchedule = Cron.EverySomeSeconds(10); o.Data.Add("ID", 234343); }); }) .Build(); Console.WriteLine("Test Console Starting..."); host.Run(); }
public void config_job_cronschedule_test() { var host = new HostBuilder() .ConfigureAppConfiguration(c => { c.AddJsonFile("appsettings.json", optional: true); }) .ConfigureServices(s => { s.AddQuartz().AddJob <MyJob>(); }) .Build(); host.Start(); var scheduler = host.Services.GetRequiredService <ISchedulerFactory>().GetScheduler().GetAwaiter().GetResult(); var trigger = scheduler.GetTriggersOfJob(new JobKey("My-Id")).GetAwaiter().GetResult().First(); Assert.Equal(Cron.EverySomeSeconds(30), ((CronTriggerImpl)trigger).CronExpressionString); host.StopAsync().GetAwaiter().GetResult(); }