首页 > 解决方案 > Activiti 进程中的双倍任务

问题描述

我有一个 Activiti 代码(在 Servicemix 上使用 Camel 运行的 Activiti 5.19)在生产中运行并且面临一些特殊的问题:有时我在执行中遇到双倍任务的情况(其中一个甚至是三倍)。它似乎没有明确的模式。如果任何javascript调用服务由于某种原因两次关闭同一任务,我测试过的代码会引发异常。

加倍的任务既不能完成(导致“用户任务在完成之前不应发出信号”异常)也不能被删除,因为这些任务是正在运行的执行的一部分。

我无法弄清楚是什么可能导致这种影响以及如何摆脱冗余任务以完成损坏的流程。

是否可以只删除 act_ru_task 中后面的记录(具有最高任务 ID)?

有人可以帮忙吗?

<?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">
    <collaboration id="Collaboration">
        <participant id="pool1" name="Pool" processRef="process_pool1"></participant>
    </collaboration>
     <process id="new_marketing" name="marketing" isExecutable="true" activiti:candidateStarterGroups="marketing,task_manager">
    <laneSet id="laneSet_new_marketing">
      <lane id="lane1" name="marketing">
        <flowNodeRef>usertask1</flowNodeRef>
        <flowNodeRef>startevent1</flowNodeRef>
        <flowNodeRef>exclusivegateway1</flowNodeRef>
        <flowNodeRef>usertask2</flowNodeRef>
        <flowNodeRef>usertask3</flowNodeRef>
        <flowNodeRef>usertask4</flowNodeRef>
        <flowNodeRef>endevent1</flowNodeRef>
        <flowNodeRef>exclusivegateway2</flowNodeRef>
        <flowNodeRef>exclusivegateway3</flowNodeRef>
        <flowNodeRef>usertask5</flowNodeRef>
        <flowNodeRef>usertask6</flowNodeRef>
        <flowNodeRef>endevent2</flowNodeRef>
      </lane>
    </laneSet>

    <startEvent id="startevent1" name="Start"></startEvent>

    <userTask id="usertask1" name="Status_0" activiti:assignee="${employeeName}" activiti:candidateGroups="marketing" activiti:dueDate="${dueDate}">
      <extensionElements>
        <activiti:formProperty id="actionsForm" name="actions" type="enum" writable="false">
          <activiti:value id="cancel" name="cancel"></activiti:value>
          <activiti:value id="accepted" name="accepted"></activiti:value>
          <activiti:value id="wait" name="wait"></activiti:value>
        </activiti:formProperty>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow12" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>

    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow1" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow>
    <userTask id="usertask2" name="Status_10" activiti:assignee="${employeeName}">
        <extensionElements>
            <activiti:formProperty id="actionsForm" name="actions" type="enum" writable="false">
              <activiti:value id="cancel" name="cancel"></activiti:value>
              <activiti:value id="proceed" name="proceed"></activiti:value>
              <activiti:value id="application" name="application"></activiti:value>
              <activiti:value id="accepted" name="accepted"></activiti:value>
              <activiti:value id="wait" name="wait"></activiti:value>
            </activiti:formProperty>
        </extensionElements>
    </userTask>
    <sequenceFlow id="flow2" sourceRef="exclusivegateway1" targetRef="usertask2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'accepted'}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="usertask3" name="Status_1" activiti:assignee="${employeeName}" activiti:dueDate="${dueDate}"></userTask>
    <sequenceFlow id="flow3" name="Wait" sourceRef="exclusivegateway1" targetRef="usertask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'wait'}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="usertask3" targetRef="usertask1"></sequenceFlow>
    <userTask id="usertask4" name="Status_1000" activiti:assignee="${employeeName}"></userTask>
    <sequenceFlow id="flow5" name="GiveUp" sourceRef="exclusivegateway1" targetRef="usertask4">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'cancel'}]]></conditionExpression>
    </sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow6" sourceRef="usertask4" targetRef="endevent1"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow7" sourceRef="usertask2" targetRef="exclusivegateway2"></sequenceFlow>

    <endEvent id="endevent2" name="End"></endEvent>

    <sequenceFlow id="flow10" sourceRef="exclusivegateway2" targetRef="usertask2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'wait'}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow11" name="GiveUp" sourceRef="exclusivegateway2" targetRef="usertask4">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'cancel'}]]></conditionExpression>
    </sequenceFlow>


    <sequenceFlow id="flow8" sourceRef="exclusivegateway2" targetRef="usertask5">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'application'}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow13" sourceRef="exclusivegateway2" targetRef="usertask6">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'proceed' || action == 'accepted'}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="usertask5" name="Status_50" activiti:assignee="${employeeName}">
        <extensionElements>
            <activiti:formProperty id="actionsForm" name="actions" type="enum" writable="false">
              <activiti:value id="cancel" name="cancel"></activiti:value>
              <activiti:value id="accepted" name="accepted"></activiti:value>
            </activiti:formProperty>
        </extensionElements>
    </userTask>

    <sequenceFlow id="flow14" sourceRef="usertask5" targetRef="exclusivegateway3"></sequenceFlow>

    <exclusiveGateway id="exclusivegateway3" name="Exclusive Gateway"></exclusiveGateway>

    <sequenceFlow id="flow15" sourceRef="exclusivegateway3" targetRef="usertask6">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'accepted'}]]></conditionExpression>
    </sequenceFlow>

    <userTask id="usertask6" name="Status_90" activiti:assignee="${employeeName}"></userTask>

    <sequenceFlow id="flow17" sourceRef="usertask6" targetRef="endevent2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'accepted'}]]></conditionExpression>
    </sequenceFlow>

    <sequenceFlow id="flow16" sourceRef="exclusivegateway3" targetRef="usertask4">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${action == 'cancel'}]]></conditionExpression>
    </sequenceFlow>

  </process>
</definitions>

使用以下查询在 Activiti 数据库中检查了该问题:

select * from act_ru_task t0 where t0.execution_id_ in (select id_ from act_ru_execution t1 where (select count(*) from act_ru_task t2 where t1.id_ = t2.execution_id_) > 1);

查询呈现了 30 个这样的案例,其中 3 个以下(用户登录匿名):

     id_    | rev_ | execution_id_ | proc_inst_id_ |     proc_def_id_     |    name_    | parent_task_id_ | description_ | task_def_key_ | owner_ |  assignee_   |delegation_   | priority_ |      create_time_       |
     118399 |    1 | 118373        | 118373        | new_marketing:3:5004 | Status_50   |                 |              | usertask5     |        | auser        |              |        50 | 2017-08-08 08:46:28.771 |
     118396 |    1 | 118373        | 118373        | new_marketing:3:5004 | Status_50   |                 |              | usertask5     |        | auser        |              |        50 | 2017-08-08 08:46:28.769 |
     634792 |    1 | 453636        | 453636        | new_marketing:3:5004 | Status_1000 |                 |              | usertask4     |        | buser        |              |        50 | 2018-04-04 09:49:13.853 |
     634791 |    1 | 453636        | 453636        | new_marketing:3:5004 | Status_1000 |                 |              | usertask4     |        | buser        |              |        50 | 2018-04-04 09:49:13.853 |
     527864 |    1 | 527837        | 527837        | new_marketing:3:5004 | Status_90   |                 |              | usertask6     |        | cuser        |              |        50 | 2018-02-01 16:06:56.089 |
     527867 |    1 | 527837        | 527837        | new_marketing:3:5004 | Status_90   |                 |              | usertask6     |        | cuser        |              |        50 | 2018-02-01 16:06:56.092 |

标签: apache-camelactivitiapache-servicemix

解决方案


推荐阅读