【问题标题】:Quartz.net version 2.3.3 - setting up AdoJobStoreQuartz.net 2.3.3 版 - 设置 AdoJobStore
【发布时间】:2016-03-24 02:06:19
【问题描述】:

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

我有工作和触发部件,但我想将其设置为使用AdoJobStore,这样这些工作就不会丢失(以防出现不需要提醒的情况)发送一两个月)。

我尝试过使用他们的官方教程、此处的一些相关帖子以及通过 google 找到的其他指南,但我根本不知道如何进行设置。大多数提供需要添加到某种配置文件的代码,但我似乎找不到任何代码 - 我看到他们说要编辑 quartz.configweb.configquartz.properties。我只能在 ASP.net 我的项目中找到 web.config,但我似乎无法在此文件中找到任何示例。

【问题讨论】:

    标签: c# asp.net quartz.net


    【解决方案1】:

    您需要在 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);
    

    【讨论】:

    • 谢谢,我一定会试试这个(希望我早点看到这个)。我只想先确认这适用于 Web 应用程序吗?现在,我遇到的唯一问题是随着时间的推移 Web 应用程序会死掉或其他什么,所以我设置为每周运行一次的作业也会死掉并且无法运行。我尝试制作一个每 10 分钟触发一次的作业,它调用一个 WebRequest 到一个随机页面,希望它能让 Web 应用程序保持活动状态,以便这些作业可以随着时间的推移持续存在,但它似乎没有工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    相关资源
    最近更新 更多