Пример #1
0
        public void inline_job_cronschedule_test()
        {
            var host = new HostBuilder()
                       .ConfigureServices(s =>
            {
                s.AddQuartz().AddJob <MyJob>(o =>
                {
                    o.Identity     = "My-Id";
                    o.CronSchedule = Cron.EveryHour();
                });
            })
                       .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.EveryHour(), ((CronTriggerImpl)trigger).CronExpressionString);
            host.StopAsync().GetAwaiter().GetResult();
        }
Пример #2
0
        public void inline_job_must_exist()
        {
            var host = new HostBuilder()
                       .ConfigureServices(s =>
            {
                s.AddQuartz().AddJob <MyJob>(o =>
                {
                    o.Identity     = "My-Id";
                    o.CronSchedule = Cron.EveryHour();
                });
            })
                       .Build();

            host.Start();

            var scheduler = host.Services.GetRequiredService <ISchedulerFactory>().GetScheduler().GetAwaiter().GetResult();

            Assert.True(scheduler.CheckExists(new JobKey("My-Id")).GetAwaiter().GetResult());

            host.StopAsync().GetAwaiter().GetResult();
        }
Пример #3
0
        public void inline_job_data_test()
        {
            var host = new HostBuilder()
                       .ConfigureServices(s =>
            {
                s.AddQuartz().AddJob <MyJob>(o =>
                {
                    o.Identity     = "My-Id";
                    o.CronSchedule = Cron.EveryHour();
                    o.Data.Add("MyData", 123);
                });
            })
                       .Build();

            host.Start();

            var scheduler = host.Services.GetRequiredService <ISchedulerFactory>().GetScheduler().GetAwaiter().GetResult();
            var job       = scheduler.GetJobDetail(new JobKey("My-Id")).GetAwaiter().GetResult();

            Assert.True(job.JobDataMap.ContainsKey("MyData"));
            Assert.Equal(123, job.JobDataMap.GetInt("MyData"));
            host.StopAsync().GetAwaiter().GetResult();
        }