groovy 是否可以为camunda中间计时器捕获事件分配一个随机时间?

9avjhtql  于 2022-11-01  发布在  其他
关注(0)|答案(1)|浏览(196)

在我的camunda进程中,我想使用一个计时器捕获事件来等待一个5-15秒之间的随机持续时间。是否可以将此随机持续时间分配给事件?

t98cgbkg

t98cgbkg1#

您可以使用类型为 javascirpt 的脚本任务来生成如下所示的值:

"PT" + Math.floor(Math.random() * 11 +5) + "S";

并将其存储在结果过程数据中。随后在时间表达式中引用该数据,如下所示:


# {timer}

示例型号:
<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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_0fr9mxs" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.1.0">输入<bpmn:process id="ExampleprocessProcess" name="example-process" isExecutable="true"><bpmn:endEvent id="EndEvent_0x6ir2l">流_09qj0b7</bpmn:incoming></bpmn:endEvent><bpmn:sequenceFlow id="Flow_09qj0b7" sourceRef="Event_18ugk9p" targetRef="EndEvent_0x6ir2l" /><bpmn:intermediateCatchEvent id="Event_18ugk9p">输入<bpmn:extensionElements />序列流_16gzt2m</bpmn:incoming>输出流_09qj0b7</bpmn:outgoing> <bpmn:timerEventDefinition id="TimerEventDefinition_0shqn5w"> <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">#{定时器}</bpmn:timeDuration></bpmn:timerEventDefinition></bpmn:intermediateCatchEvent><bpmn:scriptTask id="CreateRandomTimeTask" name="create random time" scriptFormat="javascript" camunda:resultVariable="timer">输入<bpmn:extensionElements />流_1x8rlyg</bpmn:incoming>输出序列流_16gzt2m</bpmn:outgoing>输出流:脚本“PT”+数学下限(数学随机数()* 11 + 5)+“S”</bpmn:script></bpmn:scriptTask><bpmn:sequenceFlow id="SequenceFlow_16gzt2m" sourceRef="CreateRandomTimeTask" targetRef="Event_18ugk9p" /><bpmn:startEvent id="Event_0luae7f">;输出流_1x8rlyg</bpmn:outgoing></bpmn:startEvent><bpmn:sequenceFlow id="Flow_1x8rlyg" sourceRef="Event_0luae7f" targetRef="CreateRandomTimeTask" /></bpmn:process><bpmndi:BPMNDiagram id="BPMNDiagram_1"><bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="ExampleprocessProcess"><bpmndi:BPMNEdge id="SequenceFlow_16gzt2m_di" bpmnElement="SequenceFlow_16gzt2m"><di:waypoint x="370" y="117" /><di:waypoint x="432" y="117" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_09qj0b7_di" bpmnElement="Flow_09qj0b7"><di:waypoint x="468" y="117" /><di:waypoint x="522" y="117" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_1x8rlyg_di" bpmnElement="Flow_1x8rlyg"><di:waypoint x="188" y="117" /><di:waypoint x="270" y="117" /></bpmndi:BPMNEdge><bpmndi:BPMNShape id="Event_07yj7bl_di" bpmnElement="Event_18ugk9p"><dc:Bounds x="432" y="99" width="36" height="36" /></bpmndi:BPMNShape><bpmndi:BPMNShape id="Activity_1ws8xyt_di" bpmnElement="CreateRandomTimeTask"><dc:Bounds x="270" y="77" width="100" height="80" /><bpmndi:BPMNLabel /></bpmndi:BPMNShape><bpmndi:BPMNShape id="Event_0luae7f_di" bpmnElement="Event_0luae7f"><dc:Bounds x="152" y="99" width="36" height="36" /></bpmndi:BPMNShape><bpmndi:BPMNShape id="EndEvent_0x6ir2l_di" bpmnElement="EndEvent_0x6ir2l"><dc:Bounds x="522" y="99" width="36" height="36" /></bpmndi:BPMNShape></bpmndi:BPMNPlane></bpmndi:BPMNDiagram></bpmn:definitions>

相关问题