AnsweredAssumed Answered

Process with error handling

Question asked by ercancelik on Aug 18, 2014
Latest reply on Aug 19, 2014 by martin.grofcik
Hi all,

I want to design a basic process that sends sms to user(Indeed it is a part of a big process). If the service task that sends sms throws exception i want to try 3 times with 1 minute interval. If the sms couldn't sent i want to end process(or go to next step). I designed a process like in the attachment. But after trying to send sms twice, the process suspended and waits in dummySmsST service task.

1) In Start Event, i add an alfresco script that sets retryCount variable to zero.
   
execution.setVariable("retryCount",0);


2) In dummySmsST i call the service that sends sms.

3) There is a boundaryerror attached to dummySmsST.

4) When exception occurs process goes to Receive Task. In Receive Task the retry count is increased by 1.
   
execution.setVariable("retryCount",retryCount+1);


5) In boundaryTimer attached to Receive Task, i set the time duration to PT1M.

6) In Gateway's left flow i added a condition that checks for retryCount.
   
${retryCount<3}


7) In Gateway's right flow(default flow) i do nothing. It goes to endevent.

Is there any design problem or script problem. I need your suggestions.

Here is the log :

{
    "processInstanceId": "abf33136-269d-11e4-9d17-a0a8cd68a415",
    "businessKey": null,
    "processDefinitionId": "TestSMS:2:704",
    "startTime": "2014-08-18T09:05:36EEST",
    "startActivityId": "startevent1",
    "startUserId": "kermit",
    "completed": false,
    "activities": [
        {
            "activityId": "startevent1",
            "activityName": "Start",
            "activityType": "startEvent",
            "startTime": "2014-08-18T09:05:36EEST",
            "completed": true,
            "endTime": "2014-08-18T09:05:37EEST",
            "duration": 653
        },
        {
            "activityId": "dummySmsST",
            "activityName": "dummySmsST",
            "activityType": "serviceTask",
            "startTime": "2014-08-18T09:05:47EEST",
            "completed": true,
            "endTime": "2014-08-18T09:05:52EEST",
            "duration": 5129
        },
        {
            "activityId": "boundaryerror1",
            "activityName": "Error",
            "activityType": "boundaryError",
            "startTime": "2014-08-18T09:05:52EEST",
            "completed": true,
            "endTime": "2014-08-18T09:05:52EEST",
            "duration": 0
        },
        {
            "activityId": "receivetask1",
            "activityName": "Receive Task",
            "activityType": "receiveTask",
            "startTime": "2014-08-18T09:05:52EEST",
            "completed": true,
            "endTime": "2014-08-18T09:06:52EEST",
            "duration": 60043
        },
        {
            "activityId": "boundarytimer2",
            "activityName": "Timer",
            "activityType": "boundaryTimer",
            "startTime": "2014-08-18T09:06:52EEST",
            "completed": true,
            "endTime": "2014-08-18T09:06:52EEST",
            "duration": 0
        },
        {
            "activityId": "exclusivegateway1",
            "activityName": "Exclusive Gateway",
            "activityType": "exclusiveGateway",
            "startTime": "2014-08-18T09:06:52EEST",
            "completed": true,
            "endTime": "2014-08-18T09:06:52EEST",
            "duration": 6
        },
        {
            "activityId": "dummySmsST",
            "activityName": "dummySmsST",
            "activityType": "serviceTask",
            "startTime": "2014-08-18T09:06:52EEST",
            "completed": true,
            "endTime": "2014-08-18T09:06:58EEST",
            "duration": 5972
        },
        {
            "activityId": "boundaryerror1",
            "activityName": "Error",
            "activityType": "boundaryError",
            "startTime": "2014-08-18T09:06:58EEST",
            "completed": true,
            "endTime": "2014-08-18T09:06:58EEST",
            "duration": 0
        },
        {
            "activityId": "receivetask1",
            "activityName": "Receive Task",
            "activityType": "receiveTask",
            "startTime": "2014-08-18T09:06:58EEST",
            "completed": true,
            "endTime": "2014-08-18T09:07:58EEST",
            "duration": 60058
        },
        {
            "activityId": "boundarytimer2",
            "activityName": "Timer",
            "activityType": "boundaryTimer",
            "startTime": "2014-08-18T09:07:58EEST",
            "completed": true,
            "endTime": "2014-08-18T09:07:58EEST",
            "duration": 0
        },
        {
            "activityId": "exclusivegateway1",
            "activityName": "Exclusive Gateway",
            "activityType": "exclusiveGateway",
            "startTime": "2014-08-18T09:07:58EEST",
            "completed": true,
            "endTime": "2014-08-18T09:07:58EEST",
            "duration": 10
        }
    ],
    "variables": [
        {
            "variableName": "errorTaskId",
            "variableValue": "dummySmsST"
        },
        {
            "variableName": "errorTaskName",
            "variableValue": "dummySmsST"
        },
        {
            "variableName": "errorData",
            "variableValue": null
        },
        {
            "variableName": "retryCount",
            "variableValue": 2
        },
        {
            "variableName": "OrderId",
            "variableValue": "aae97bfe-590c-40ed-af6f-77906d6d4014"
        },
        {
            "variableName": "errorCode",
            "variableValue": "smsTypeNotFound"
        }
    ],
    "historyVariables": [
        {
            "variableName": "retryCount",
            "variableValue": 2,
            "variableType": "integer",
            "revision": 2,
            "time": "2014-08-18T09:06:58EEST"
        },
        {
            "variableName": "errorTaskId",
            "variableValue": "dummySmsST",
            "variableType": "string",
            "revision": 1,
            "time": "2014-08-18T09:06:58EEST"
        },
        {
            "variableName": "errorTaskName",
            "variableValue": "dummySmsST",
            "variableType": "string",
            "revision": 1,
            "time": "2014-08-18T09:06:58EEST"
        },
        {
            "variableName": "errorData",
            "variableValue": null,
            "variableType": "null",
            "revision": 1,
            "time": "2014-08-18T09:06:58EEST"
        },
        {
            "variableName": "errorCode",
            "variableValue": "smsTypeNotFound",
            "variableType": "string",
            "revision": 1,
            "time": "2014-08-18T09:06:58EEST"
        },
        {
            "variableName": "retryCount",
            "variableValue": 1,
            "variableType": "integer",
            "revision": 1,
            "time": "2014-08-18T09:05:52EEST"
        },
        {
            "variableName": "errorTaskId",
            "variableValue": "dummySmsST",
            "variableType": "string",
            "revision": 0,
            "time": "2014-08-18T09:05:52EEST"
        },
        {
            "variableName": "errorTaskName",
            "variableValue": "dummySmsST",
            "variableType": "string",
            "revision": 0,
            "time": "2014-08-18T09:05:52EEST"
        },
        {
            "variableName": "errorData",
            "variableValue": null,
            "variableType": "null",
            "revision": 0,
            "time": "2014-08-18T09:05:52EEST"
        },
        {
            "variableName": "errorCode",
            "variableValue": "smsTypeNotFound",
            "variableType": "string",
            "revision": 0,
            "time": "2014-08-18T09:05:52EEST"
        },
        {
            "variableName": "retryCount",
            "variableValue": 0,
            "variableType": "integer",
            "revision": 0,
            "time": "2014-08-18T09:05:37EEST"
        },
        {
            "variableName": "OrderId",
            "variableValue": "aae97bfe-590c-40ed-af6f-77906d6d4014",
            "variableType": "string",
            "revision": 0,
            "time": "2014-08-18T09:05:36EEST"
        }
    ]
}


And the xml code of bpmn :


<?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="TestSMS" name="TestSMS" isExecutable="true">
    <startEvent id="startevent1" name="Start">
      <extensionElements>
        <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[execution.setVariable("retryCount",0);]]></activiti:string>
          </activiti:field>
        </activiti:executionListener>
      </extensionElements>
    </startEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="dummySmsST"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="dummySmsST" targetRef="endevent1"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" default="flow6"></exclusiveGateway>
    <sequenceFlow id="flow5" sourceRef="exclusivegateway1" targetRef="dummySmsST">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${retryCount<3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="exclusivegateway1" targetRef="endevent1"></sequenceFlow>
    <serviceTask id="dummySmsST" name="dummySmsST" activiti:async="true" activiti:class="bpm.engine.delegates.GatewayServiceDelegate">
      <extensionElements>
        <activiti:field name="serviceName">
          <activiti:string><![CDATA[SmsOperationsV1Plugin.sendDummySms]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <boundaryEvent id="boundaryerror1" name="Error" attachedToRef="dummySmsST">
      <errorEventDefinition></errorEventDefinition>
    </boundaryEvent>
    <sequenceFlow id="flow9" sourceRef="boundaryerror1" targetRef="receivetask1"></sequenceFlow>
    <sequenceFlow id="flow11" sourceRef="boundarytimer2" targetRef="exclusivegateway1"></sequenceFlow>
    <receiveTask id="receivetask1" name="Receive Task">
      <extensionElements>
        <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[execution.setVariable("retryCount",retryCount+1);]]></activiti:string>
          </activiti:field>
        </activiti:executionListener>
      </extensionElements>
    </receiveTask>
    <boundaryEvent id="boundarytimer2" name="Timer" attachedToRef="receivetask1" cancelActivity="true">
      <timerEventDefinition>
        <timeDuration>PT1M</timeDuration>
      </timerEventDefinition>
    </boundaryEvent>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_TestSMS">
    <bpmndi:BPMNPlane bpmnElement="TestSMS" id="BPMNPlane_TestSMS">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="60.0" y="70.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="510.0" y="70.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="395.0" y="123.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="dummySmsST" id="BPMNShape_dummySmsST">
        <omgdc:Bounds height="55.0" width="105.0" x="220.0" y="60.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="boundaryerror1" id="BPMNShape_boundaryerror1">
        <omgdc:Bounds height="30.0" width="30.0" x="260.0" y="100.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="receivetask1" id="BPMNShape_receivetask1">
        <omgdc:Bounds height="55.0" width="105.0" x="222.0" y="181.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="boundarytimer2" id="BPMNShape_boundarytimer2">
        <omgdc:Bounds height="30.0" width="30.0" x="292.0" y="221.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="95.0" y="87.0"></omgdi:waypoint>
        <omgdi:waypoint x="220.0" y="87.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="325.0" y="87.0"></omgdi:waypoint>
        <omgdi:waypoint x="510.0" y="87.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="395.0" y="143.0"></omgdi:waypoint>
        <omgdi:waypoint x="272.0" y="115.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="415.0" y="123.0"></omgdi:waypoint>
        <omgdi:waypoint x="527.0" y="105.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
        <omgdi:waypoint x="275.0" y="130.0"></omgdi:waypoint>
        <omgdi:waypoint x="274.0" y="181.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
        <omgdi:waypoint x="322.0" y="236.0"></omgdi:waypoint>
        <omgdi:waypoint x="415.0" y="235.0"></omgdi:waypoint>
        <omgdi:waypoint x="415.0" y="163.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


Thank you.

Outcomes