设为首页 加入收藏

TOP

使用mongodb作为Quartz.Net下的JobStore实现底层的持久化机制(三)
2017-10-13 10:43:36 】 浏览:990
Tags:使用 mongodb 作为 Quartz.Net JobStore 实现 底层 持久化 机制
tring}
"] = "mongodb://192.168.23.163/quartz"; 15 16 // The prefix is optional 17 properties[$"{StdSchedulerFactory.PropertyJobStorePrefix}.collectionPrefix"] = "prefix"; 18 19 var factory = new StdSchedulerFactory(properties); 20 21 //scheduler 22 IScheduler scheduler = factory.GetScheduler(); 23 24 scheduler.Start(); 25 26 var job = JobBuilder.Create<HelloJob>().WithIdentity("test", "datamip").Build(); 27 28 var trigger = TriggerBuilder.Create().WithCronSchedule("* * * * * ?").Build(); 29 30 if (!scheduler.CheckExists(job.Key)) 31 { 32 scheduler.ScheduleJob(job, trigger); 33 } 34 35 Console.Read(); 36 }

 

这个我自定义的HelloJob中,我特意记录一下scheduler的调度时间schedulertime和Trigger应该触发的时间nextFireTime。

 1     class HelloJob : IJob
 2     {
 3         static int index = 1;
 4 
 5         public void Execute(IJobExecutionContext context)
 6         {
 7             Console.WriteLine("{4} index={0},current={1}, scheuler={2},nexttime={3}",
 8                                             index++, DateTime.Now,
 9                                             context.ScheduledFireTimeUtc?.LocalDateTime,
10                                             context.NextFireTimeUtc?.LocalDateTime,
11                                             context.JobDetail.JobDataMap["key"]);
12         }
13     }

 

接下来执行一下:

 

然后通过robomongo到数据库看一下,有5个collection,里面都有数据,没毛病。

 

好了,本篇就说到这里了,当然还有基于redis的JobStore,有兴趣大家可以自己尝试一下。

 

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇背水一战 Windows 10 (56) - 控件.. 下一篇Log4Net记录到MySql

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目