Alfresco工作流程被多次触发

时间:2017-02-03 14:02:41

标签: alfresco activiti bpmn alfresco-webscripts

我在触发工作流程时遇到问题。

我在文件夹上应用了规则

规则的定义:

i)在输入此文件夹时创建项目 ii)名称以.xml结尾 iii)执行脚本

脚本

function startWorkflow()
{
var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "activiti$Excel_initial_service";
workflow.parameters["bpm:workflowDescription"] = "Excel initial      service workflow for : " + document.name;
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 1);
workflow.parameters["bpm:workflowDueDate"] = futureDate;
return workflow.execute(document);
}

function main()
{
startWorkflow();
}

main();

我的工作流程定义是

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"   xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">

<process id="Excel_initial_service" name="Excel Initial Service"    isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
 .
 .
 .
 .

<serviceTask id="servicetask1" name="Service Task" activiti:class="*">  </serviceTask>
 .
 .
 .
 .

我面临的问题是服务任务在文件夹中输入的单个文件被多次触发并且没有被停止。

<?xml version="1.0" encoding="UTF-8"?>

<process id="***" name="Excel Generation Service" isExecutable="true">
<startEvent id="starteventexcel1" name="Start"></startEvent>

<intermediateCatchEvent id="timerintermediatecatcheventexcel1" name="TimerCatchEvent1">
  <timerEventDefinition>
    <timeDuration>PT10S</timeDuration>
  </timerEventDefinition>
</intermediateCatchEvent>

<serviceTask id="servicetaskexcel1" name="Service Task" activiti:class="***"></serviceTask>

<intermediateCatchEvent id="timerintermediatecatcheventexcel2" name="TimerCatchEvent2">
  <timerEventDefinition>
    <timeDuration>PT10S</timeDuration>
  </timerEventDefinition>
</intermediateCatchEvent>



<endEvent id="endeventexcel1" name="End"></endEvent>
<sequenceFlow id="flowexcel1" sourceRef="starteventexcel1" targetRef="timerintermediatecatcheventexcel1"></sequenceFlow>
<sequenceFlow id="flowexcel2" sourceRef="timerintermediatecatcheventexcel1" targetRef="servicetaskexcel1"></sequenceFlow>
<sequenceFlow id="flowexcel3" sourceRef="servicetaskexcel1" targetRef="timerintermediatecatcheventexcel2"></sequenceFlow>
<sequenceFlow id="flowexcel4" sourceRef="timerintermediatecatcheventexcel2" targetRef="endeventexcel1"></sequenceFlow>

</process>

2 个答案:

答案 0 :(得分:0)

此处的第一个intermediateCatchEvent将每10秒执行一次服务任务。为何使用它?

答案 1 :(得分:0)

这个答案可能会对你有帮助。

要使用的类是ClockUtil,它会更改引擎的内部时钟。

话虽如此,我检查了你的测试,我发现你正在使用

ProcessEngine eng = ProcessEngineConfiguration
       .createStandaloneInMemProcessEngineConfiguration()
       .buildProcessEngine();

获取流程引擎。这将为您提供默认引擎,并禁用作业执行程序。定时器执行需要作业执行程序。添加以下行以构建流程引擎以使其工作:

setJobExecutorActivate(true);

您可以参考此问题https://community.alfresco.com/thread/219801-problem-with-intermediatecatchevent

您将在github上找到一些代码,如上面提到的问题https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/test/java/org/activiti/engine/test/bpmn/event/timer/IntermediateTimerEventTest.java

中所述