当前位置:网站首页>Camunda timer events example demo (timer events)

Camunda timer events example demo (timer events)

2022-06-13 11:38:00 I'm not a fat tiger

Camunda Timer event (Timer Events) Is an event triggered by a defined timer . They can be used as start events 、 Intermediate event or boundary event . Boundary events can interrupt , It can also be uninterrupted .

Camunda Timer events include :Timer Start Event( Timed start events )、Timer Intermediate Catching Event( Timing intermediate capture events )、Timer Boundary Event( Timed boundary Events ).

Timer start event Timer Start Event Used to create process instances at a given time . It can be used for processes that should only be started once , It can also be used for processes that should be started within a specific time interval . Subprocesses cannot have timer start events . Once the process is deployed , The timer start event is scheduled . There is no need to call startProcessInstanceBy…, Just call start Process methods are unrestricted , And will result in startProcessInstanceBy Start the process again … call . Timer start event XML Indicates a normal start event declaration , Child elements with timer definitions .

Timer boundary Events Timer Boundary Event Act as a stopwatch and alarm clock . When performing an activity that reaches an additional boundary event , The timer will start . When the timer triggers ( for example , After the specified time interval ), Activity interrupted , Then the sequence stream leaves the timer boundary event . There is a difference between interrupt and non interrupt timer events . By default, it is an interrupt event . A non disruptive event causes the original activity not to be interrupted , The activity stays there . contrary , An additional execution will be created and sent in the outgoing transformation of the event .

This article focuses on Timer Start Event( Timed start events ) and Timer Boundary Event( Timed boundary Events ), For other events, please refer to camunda Official documents :https://docs.camunda.org/manual/7.15/reference/bpmn20/events/

 

One 、 Design flow chart

 

 

Timer start event Timer Start Event Node configuration :

 

      <bpmn:timerEventDefinition id="TimerEventDefinition_14ilbim">

        <bpmn:timeCycle xsi:type="bpmn:tFormalExpression">R2/2022-02-11T09:07/PT1M</bpmn:timeCycle>

      </bpmn:timerEventDefinition>

Indicates that the process will start on 2022 year 2 month 11 Japan 09:07(24 hourly ) Start , With 1 Minutes apart , Start up 2 Time .

 

Timer boundary Events Timer Boundary Event Node configuration


 

      <bpmn:timerEventDefinition id="TimerEventDefinition_1epfipx">

        <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT3M</bpmn:timeDuration>

      </bpmn:timerEventDefinition>

Indicates that the process timed out at the task node 3 Minutes unprocessed will flow automatically .

 

BPMN Process model file :

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

<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1gaqb29" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.8.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">

  <bpmn:process id="Process_1hroby5" name=" Timer flow " isExecutable="true">

    <bpmn:sequenceFlow id="Flow_0w5epa1" sourceRef="StartEvent_1" targetRef="Activity_1bxm9f3" />

    <bpmn:sequenceFlow id="Flow_0rzgepj" sourceRef="Activity_1bxm9f3" targetRef="Activity_0wkolx8" />

    <bpmn:endEvent id="Event_1avte49">

      <bpmn:incoming>Flow_0a2yjox</bpmn:incoming>

    </bpmn:endEvent>

    <bpmn:sequenceFlow id="Flow_0a2yjox" sourceRef="Activity_0wkolx8" targetRef="Event_1avte49" />

    <bpmn:userTask id="Activity_1bxm9f3" name=" Task a " camunda:assignee="demo">

      <bpmn:incoming>Flow_0w5epa1</bpmn:incoming>

      <bpmn:outgoing>Flow_0rzgepj</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:userTask id="Activity_0wkolx8" name=" Task 2 " camunda:assignee="demo">

      <bpmn:incoming>Flow_0rzgepj</bpmn:incoming>

      <bpmn:incoming>Flow_0gb67p8</bpmn:incoming>

      <bpmn:outgoing>Flow_0a2yjox</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:startEvent id="StartEvent_1">

      <bpmn:outgoing>Flow_0w5epa1</bpmn:outgoing>

      <bpmn:timerEventDefinition id="TimerEventDefinition_14ilbim">

        <bpmn:timeCycle xsi:type="bpmn:tFormalExpression">R2/2022-02-11T09:07/PT1M</bpmn:timeCycle>

      </bpmn:timerEventDefinition>

    </bpmn:startEvent>

    <bpmn:boundaryEvent id="Event_0m9gmvl" name=" Automatic flow over time " attachedToRef="Activity_1bxm9f3">

      <bpmn:outgoing>Flow_0gb67p8</bpmn:outgoing>

      <bpmn:timerEventDefinition id="TimerEventDefinition_1epfipx">

        <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT3M</bpmn:timeDuration>

      </bpmn:timerEventDefinition>

    </bpmn:boundaryEvent>

    <bpmn:sequenceFlow id="Flow_0gb67p8" sourceRef="Event_0m9gmvl" targetRef="Activity_0wkolx8" />

  </bpmn:process>

  <bpmndi:BPMNDiagram id="BPMNDiagram_1">

    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1hroby5">

      <bpmndi:BPMNEdge id="Flow_0a2yjox_di" bpmnElement="Flow_0a2yjox">

        <di:waypoint x="590" y="117" />

        <di:waypoint x="652" y="117" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0rzgepj_di" bpmnElement="Flow_0rzgepj">

        <di:waypoint x="370" y="117" />

        <di:waypoint x="490" y="117" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0w5epa1_di" bpmnElement="Flow_0w5epa1">

        <di:waypoint x="215" y="117" />

        <di:waypoint x="270" y="117" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0gb67p8_di" bpmnElement="Flow_0gb67p8">

        <di:waypoint x="330" y="175" />

        <di:waypoint x="330" y="195" />

        <di:waypoint x="540" y="195" />

        <di:waypoint x="540" y="157" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNShape id="Activity_18kpbpa_di" bpmnElement="Activity_1bxm9f3">

        <dc:Bounds x="270" y="77" width="100" height="80" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Event_1162jaf_di" bpmnElement="StartEvent_1">

        <dc:Bounds x="179" y="99" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_1gogmit_di" bpmnElement="Activity_0wkolx8">

        <dc:Bounds x="490" y="77" width="100" height="80" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Event_1avte49_di" bpmnElement="Event_1avte49">

        <dc:Bounds x="652" y="99" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Event_0lvm3q2_di" bpmnElement="Event_0m9gmvl">

        <dc:Bounds x="312" y="139" width="36" height="36" />

        <bpmndi:BPMNLabel>

          <dc:Bounds x="347" y="163" width="66" height="14" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNShape>

    </bpmndi:BPMNPlane>

  </bpmndi:BPMNDiagram>

</bpmn:definitions>

Two 、 Deploy the process and test and verify

 

After process deployment , View the database scheduled task definition table act_ru_jobdef, Find out timer-start-event and timer-transition Have been persisted to the database .


 

At this point, view the database scheduled task execution table act_ru_job,timer-start-event Already in place .


 

adopt demo The user login camunda platform http://localhost:8080/camunda/app/tasklist/default/#/login, Observe the process execution status , After discovery of arrival time , The process starts automatically , indicate Timer start event Timer Start Event It works .

 

 

Then view the database scheduled task execution table act_ru_job:

 

 

wait for 3 Minutes later , Then check the execution status of the process , It is found that the flow automatically flows to the task 2 node , explain Timer boundary Events Timer Boundary Event It works .

 

 

3、 ... and 、 How to define timers

Use ISO 8601 Time format configuration timer . The timer definition must have exactly one of the following elements .

 

1、 Fixed time

This format follows ISO 8601 Format specifies the fixed time and date when the trigger is triggered .

Example :

<timerEventDefinition>

  <timeDate>2011-03-11T12:13:14Z</timeDate>

</timerEventDefinition>

 

2、 The time interval

To specify how long a timer should run before it triggers , Can be timeDuration Designated as timerEventDefinition Child elements . You can use two different ISO 8601 The duration format defines the duration :

PnYnMnDTnHnMnS

PnW

for example ( The interval is 10 God ):

<timerEventDefinition>

  <timeDuration>P10D</timeDuration>

</timerEventDefinition>

 

3、 cycle time

Specify a repeat interval , This is useful for periodically starting processes or sending multiple reminders for expired user tasks . A time period element can have two formats . One option is the format of the recurrence duration , from ISO 8601 The repetition interval standard specifies .

for example (3 Repeat interval , Every last 10 Hours ):

<timerEventDefinition>

  <timeCycle>R3/PT10H</timeCycle>

</timerEventDefinition>

Besides , You can use cron The expression specifies a time period , The following example shows a trigger every 5 Minutes to trigger , Start from the full hour :

0 0/5 * * * ?

 

Reference resources :

Timer Events | docs.camunda.org

https://docs.camunda.org/manual/7.15/user-guide/process-engine/the-job-executor/

原网站

版权声明
本文为[I'm not a fat tiger]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206131121515397.html