2013-02-15 5 views
0

방금 ​​Quartz.net을 사용하기 시작했습니다. 나는 나의의 app.config이전 인스턴스가 완료되지 않은 경우 quartz.net 반복 예약 된 작업이 실행되지 않습니까?

<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 분 동안 수면을 취하고 있습니다. 문제는 프로세스의 여러 인스턴스를 동시에 실행하지 않기를 바랍니다. 현재 설정에서는 60 초마다 여전히 Executing PROCESSING 메시지가 표시됩니다.

Quartz.net을 사용하여이 인스턴스를 이전 인스턴스가 완료된 후에 만 ​​실행하는 방법이 있습니까?

답변

4

여기에 [DisallowConcurrentExecution] 속성으로 작업을 표시해야합니다. 이것의 뒤에 추론/행동은 Quartz.net scheduler and IStatefulJob (IStatefulJob 마커 인터페이스는 2.0 이전에가는 길이었다)에서 설명했다.

관련 문제