0

Quartz.net を使い始めたばかりです。app.config に以下を追加することで実行できました

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

<!-- Configure Thread Pool -->
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="Normal" />

<!-- Check for updates to the scheduling every 10 seconds -->
<add key="quartz.plugin.xml.scanInterval" value="10" />

<!-- Configure Job Store -->
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
<add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz"/>
<add key="quartz.plugin.xml.fileNames" value="quartz.config" />

そして、次の Quartz.config を追加しました。

<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                version="2.0">
  <processing-directives>
    <overwrite-existing-data>true</overwrite-existing-data>
  </processing-directives>

  <schedule>
    <job>
      <name>ResultProcessor</name>
      <group>Result</group>
      <description>Normalizes results.</description>
      <job-type>TestingNamespace.TestingJob,xxx</job-type>
    </job>

    <trigger>
      <simple>
        <name>ResultProcessorTrigger</name>
        <group>Result</group>
        <description>Trigger for result processor</description>
        <job-name>ResultProcessor</job-name>
        <job-group>Result</job-group>
        <misfire-instruction>SmartPolicy</misfire-instruction>
        <repeat-count>-1</repeat-count>
        <repeat-interval>60000</repeat-interval> <!-- Every 60 seconds -->
      </simple>
    </trigger>
  </schedule>
</job-scheduling-data>

そして、次のクラスが実行されています。

namespace TestingNamespace
{
    class TestingJob: IJob
    {
        protected static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public void Execute(IJobExecutionContext context)
        {
            try
            {
                logger.Info("Executing PROCESSING");
                Thread.Sleep(TimeSpan.FromMinutes(5));
            }
            catch (Exception ex)
            {
                logger.Error("Problem running Execute.", ex);
                throw;
            } // End of catch
        } // End of Run
    } // End of TestingJob
} // End of namespace

ジョブでわかるように、ジョブThread.Sleep(TimeSpan.FromMinutes(5));を 5 分間スリープさせます。問題は、プロセスの複数のインスタンスを一度に実行したくないということです。現在のセットアップでは、まだExecuting PROCESSING60 秒ごとにメッセージが表示されます。

Quartz.net を使用して、前のインスタンスが終了した後にのみこのジョブを実行する方法はありますか?

4

1 に答える 1

4

これは、 [DisallowConcurrentExecution]属性でジョブをマークする必要がある場所です。この背後にある理由/動作は、こちらQuartz.net スケジューラーと IStatefulJobで説明されています (IStatefulJob マーカー インターフェイスは 2.0 より前の方法でした)。

于 2013-02-15T21:13:16.957 に答える