Quartz.net 2.3.3版 - 设置AdoJobStore

时间:2016-03-22 01:05:26

标签: c# asp.net quartz.net

我使用ASP.Net网站作为一种后端控制面板,我想设置它,以便当用户向我的数据库添加内容时,它将创建/安排作业发送在某个日期提醒所有人。

我有工作并触发部分工作,但是我想将其设置为使用AdoJobStore以便这些工作不会丢失(如果有一个提醒没有的实例)必须被送出一整个月或两个月)。

我已经尝试过使用他们的官方教程,这里的一些相关帖子,以及我通过谷歌找到的其他指南,但我无法弄清楚如何设置它。大多数提供的代码需要添加到某种配置文件中,但我似乎无法找到 - 我看到他们说要编辑quartz.configweb.configquartz.properties 。我只能在web.config我的项目中找到ASP.net,但我似乎无法在此文件中找到任何示例。

1 个答案:

答案 0 :(得分:2)

您需要在app.config / web.config中定义ADOJobStore,然后在quartz.config中定义。我称之为QuartzDataStoreSettingsDatabase.config

<configSections>
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />

</configSections>


<quartz configSource="QuartzDataStoreSettingsDatabase.config" />

然后是石英特定东西的文件

QuartzDataStoreSettingsDatabase.config

<quartz>
<add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzSchedulerFromConfigFileSqlServer"/>
<add key="quartz.scheduler.instanceId" value="instance_one"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="Normal"/>

<!-- 
org.quartz.scheduler.idleWaitTime
Is the amount of time in milliseconds that the scheduler will wait before re-queries for available triggers when the scheduler is otherwise idle. Normally you should not have to 'tune' this parameter, unless you're using XA transactions, and are having problems with delayed firings of triggers that should fire immediately.
It defaults to every 30 seconds until it finds a trigger. Once it finds any triggers, it gets the time of the next trigger to fire and stops checking until then, unless a trigger changes.   -->
<add key="quartz.scheduler.idleWaitTime" value ="5000"/>

<!-- Misfire : see http://nurkiewicz.blogspot.com/2012/04/quartz-scheduler-misfire-instructions.html  -->
<add key="quartz.jobStore.misfireThreshold" value="60000"/>
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"/>
<add key="quartz.jobStore.tablePrefix" value="QRTZ_"/>
<add key="quartz.jobStore.clustered" value="false"/>
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz"/>


<add key="quartz.jobStore.dataSource" value="MySqlServerFullVersion"/>
<add key="quartz.jobStore.useProperties" value="false"/>

<add key="quartz.dataSource.MySqlServerFullVersion.connectionString" value="SuperSecret!!"/>
<add key="quartz.dataSource.MySqlServerFullVersion.provider" value="SqlServer-20"/>
</quartz>

请在此处查看我的回答:

Unable to save anything to the Quartz.net ado store

然后当您的网站世界发生“事件”时......您需要以编程方式安排工作。

            NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("quartz");

            ShowConfiguration(config, logger);

            ISchedulerFactory factory = new StdSchedulerFactory(config);

            IScheduler sched = factory.GetScheduler();


/* the below code has to be tweaked for YOUR Job */
        IJobDetail textFilePoppingJobJobDetail = JobBuilder.Create<TextFilePoppingNonConcurrentJob>()
            .WithIdentity("textFilePoppingJobJobDetail001", "groupName007")
                            .UsingJobData("JobDetailParameter001", "Abcd1234")
            .Build();


        ITrigger textFilePoppingJobJobDetailTrigger001 = TriggerBuilder.Create()
          .WithIdentity("textFilePoppingJobJobDetailTrigger001", "groupName007")
          .UsingJobData("TriggerParameter001", "Bcde2345")
          .UsingJobData("TempDirectorySubFolderName", "MyTempDirectorySubFolderName")
          .UsingJobData("DestinationFullFolderName", @"C:\SomeFolder")
          .StartNow()
          .WithSimpleSchedule(x => x
              .WithIntervalInSeconds(10)
              .RepeatForever()
            /* .WithRepeatCount(1) */
              )
          .Build();

        sched.ScheduleJob(textFilePoppingJobJobDetail, textFilePoppingJobJobDetailTrigger001);