Esempio n. 1
0
        /// <summary>
        /// ADO.Net
        /// </summary>
        /// <returns></returns>
        static async Task ConfigureAdo()
        {
            Jobs.QuestionJob    questionJob = new Jobs.QuestionJob();
            NameValueCollection properties  = new NameValueCollection();

            properties["quartz.scheduler.instanceName"] = "TestScheduler";
            properties["quartz.scheduler.instanceId"]   = "instance_one";
            properties["quartz.threadPool.type"]        = "Quartz.Simpl.SimpleThreadPool, Quartz";
            properties["quartz.threadPool.threadCount"] = "5";
            //properties["quartz.threadPool.threadPriority"] = "Normal";
            properties["quartz.jobStore.misfireThreshold"] = "60000";
            properties["quartz.jobStore.type"]             = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
            properties["quartz.jobStore.useProperties"]    = "false";
            properties["quartz.jobStore.dataSource"]       = "default";
            properties["quartz.jobStore.tablePrefix"]      = "QRTZ_";
            properties["quartz.serializer.type"]           = "binary";
            properties["quartz.jobStore.clustered"]        = "true";

            properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";
            // 数据库连接字符串
            properties["quartz.dataSource.default.connectionString"] = "Data Source=LICHAOQIANG-PC;Initial Catalog=Quartz;Integrated Security=True";
            properties["quartz.dataSource.default.provider"]         = "SqlServer";//3.0以上不再带版本

            ISchedulerFactory schedulerFactory = new StdSchedulerFactory(properties);
            IScheduler        scheduler        = await schedulerFactory.GetScheduler();

            await scheduler.Start();

            var jobKey = JobKey.Create("myjob8", "group");

            if (await scheduler.CheckExists(jobKey))
            {
                Console.WriteLine("当前job已经存在,无需调度:{0}", jobKey.ToString());
            }
            else
            {
                IJobDetail job = JobBuilder.Create <QuestionJob>()
                                 .WithDescription("使用quartz进行持久化存储")
                                 .StoreDurably()
                                 .RequestRecovery()
                                 .WithIdentity(jobKey)
                                 .UsingJobData("count", 1)
                                 .Build();
                //定义触发器
                ITrigger trigger = null;
                trigger = TriggerBuilder.Create().WithSimpleSchedule(x => x.WithIntervalInSeconds(2)
                                                                     .RepeatForever())
                          .Build();
                //trigger = TriggerBuilder.Create().WithCalendarIntervalSchedule((c) =>
                // {

                //     c.WithInterval(6, IntervalUnit.Month);

                // }).Build();
                scheduler.ListenerManager.AddJobListener(new Listener.JobListener());
                await scheduler.ScheduleJob(job, trigger);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// <![CDATA[通过配置文件的方式]]>
        /// </summary>
        /// <returns></returns>
        static async Task Configure()
        {
            Jobs.QuestionJob questionJob = new Jobs.QuestionJob();

            Quartz.Simpl.SimpleTypeLoadHelper     simpleTypeLoadHelper       = new Quartz.Simpl.SimpleTypeLoadHelper();
            Quartz.Xml.XMLSchedulingDataProcessor xmlSchedulingDataProcessor = new Quartz.Xml.XMLSchedulingDataProcessor(simpleTypeLoadHelper);

            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            IScheduler        scheduler        = schedulerFactory.GetScheduler().Result;
            await xmlSchedulingDataProcessor.ProcessFileAndScheduleJobs(scheduler);

            await scheduler.Start();
        }