Skip to content

Commit a21b987

Browse files
author
Tihomir Surdilovic
committed
add workflow exectimeout and keepactive
Signed-off-by: Tihomir Surdilovic <[email protected]>
1 parent 224d48c commit a21b987

File tree

8 files changed

+210
-1
lines changed

8 files changed

+210
-1
lines changed

api/src/main/java/io/serverlessworkflow/api/serializers/WorkflowSerializer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ public void serialize(Workflow workflow,
8585
workflow.getDataOutputSchema());
8686
}
8787

88+
if (workflow.getExecTimeout() != null) {
89+
gen.writeObjectField("execTimeout", workflow.getExecTimeout());
90+
}
91+
92+
if (workflow.isKeepActive()) {
93+
gen.writeBooleanField("keepActive", workflow.isKeepActive());
94+
}
95+
8896
if (workflow.getMetadata() != null && !workflow.getMetadata().isEmpty()) {
8997
gen.writeObjectField("metadata",
9098
workflow.getMetadata());
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"type": "object",
3+
"javaType": "io.serverlessworkflow.api.exectimeout.ExecTimeout",
4+
"properties": {
5+
"interval": {
6+
"type": "string",
7+
"description": "Timeout interval (ISO 8601 duration format)",
8+
"minLength": 1
9+
},
10+
"interrupt": {
11+
"type": "boolean",
12+
"description": "If `false`, workflow instance is allowed to finish current execution. If `true`, current workflow execution is abrupted.",
13+
"default": false
14+
},
15+
"runBefore": {
16+
"type": "string",
17+
"description": "Name of a workflow state to be executed before workflow instance is terminated",
18+
"minLength": 1
19+
}
20+
},
21+
"required": [
22+
"interval"
23+
]
24+
}

api/src/main/resources/schema/workflow.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
"type": "string",
4040
"description": "URI to JSON Schema that workflow data output adheres to"
4141
},
42+
"execTimeout": {
43+
"description": "Workflow execution timeout",
44+
"$ref": "exectimeout/exectimeout.json"
45+
},
46+
"keepActive": {
47+
"type": "boolean",
48+
"default": false,
49+
"description": "If 'true', workflow instances is not terminated when there are no active execution paths. Instance can be terminated via 'terminate end definition' or reaching defined 'execTimeout'"
50+
},
4251
"metadata": {
4352
"$ref": "metadata/metadata.json"
4453
},

api/src/test/java/io/serverlessworkflow/api/test/MarkupToWorkflowTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.serverlessworkflow.api.Workflow;
2020
import io.serverlessworkflow.api.actions.Action;
2121
import io.serverlessworkflow.api.defaultdef.DefaultDefinition;
22+
import io.serverlessworkflow.api.exectimeout.ExecTimeout;
2223
import io.serverlessworkflow.api.functions.FunctionDefinition;
2324
import io.serverlessworkflow.api.functions.FunctionRef;
2425
import io.serverlessworkflow.api.interfaces.State;
@@ -53,7 +54,8 @@ public class MarkupToWorkflowTest {
5354
"/examples/foreachstatewithactions.json", "/examples/foreachstatewithactions.yml",
5455
"/examples/periodicinboxcheck.json", "/examples/periodicinboxcheck.yml",
5556
"/examples/vetappointmentservice.json", "/examples/vetappointmentservice.yml",
56-
"/examples/eventbasedtransition.json", "/examples/eventbasedtransition.yml"
57+
"/examples/eventbasedtransition.json", "/examples/eventbasedtransition.yml",
58+
"/examples/roomreadings.json", "/examples/roomreadings.yml"
5759
})
5860
public void testSpecExamplesParsing(String workflowLocation) {
5961
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
@@ -236,4 +238,22 @@ public void testFunctionRefs(String workflowLocation) {
236238
assertEquals(1, functionRef2.getParameters().size());
237239
assertEquals("{{ $.customer }}", functionRef2.getParameters().get("applicant"));
238240
}
241+
242+
@ParameterizedTest
243+
@ValueSource(strings = {"/features/keepactiveexectimeout.json", "/features/keepactiveexectimeout.yml"})
244+
public void testKeepActiveExecTimeout(String workflowLocation) {
245+
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
246+
247+
assertNotNull(workflow);
248+
assertNotNull(workflow.getId());
249+
assertNotNull(workflow.getName());
250+
assertNotNull(workflow.getStates());
251+
252+
assertTrue(workflow.isKeepActive());
253+
assertNotNull(workflow.getExecTimeout());
254+
255+
ExecTimeout execTimeout = workflow.getExecTimeout();
256+
assertEquals("PT1H", execTimeout.getInterval());
257+
assertEquals("GenerateReport", execTimeout.getRunBefore());
258+
}
239259
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"id": "roomreadings",
3+
"name": "Room Temp and Humidity Workflow",
4+
"version": "1.0",
5+
"execTimeout": {
6+
"interval": "PT1H",
7+
"runBefore": "GenerateReport"
8+
},
9+
"keepActive": true,
10+
"states": [
11+
{
12+
"name": "ConsumeReading",
13+
"type": "event",
14+
"start": true,
15+
"onEvents": [
16+
{
17+
"eventRefs": ["TemperatureEvent", "HumidityEvent"],
18+
"actions": [
19+
{
20+
"functionRef": {
21+
"refName": "LogReading"
22+
}
23+
}
24+
],
25+
"eventDataFilter": {
26+
"dataOutputPath": "$.readings"
27+
}
28+
}
29+
],
30+
"end": true
31+
},
32+
{
33+
"name": "GenerateReport",
34+
"type": "operation",
35+
"actions": [
36+
{
37+
"functionRef": {
38+
"refName": "ProduceReport",
39+
"parameters": {
40+
"data": "$.readings"
41+
}
42+
}
43+
}
44+
],
45+
"end": {
46+
"terminate": true
47+
}
48+
}
49+
],
50+
"events": [
51+
{
52+
"name": "TemperatureEvent",
53+
"type": "my.home.sensors",
54+
"source": "/home/rooms/+",
55+
"correlation": [
56+
{
57+
"contextAttributeName": "roomId"
58+
}
59+
]
60+
},
61+
{
62+
"name": "HumidityEvent",
63+
"type": "my.home.sensors",
64+
"source": "/home/rooms/+",
65+
"correlation": [
66+
{
67+
"contextAttributeName": "roomId"
68+
}
69+
]
70+
}
71+
],
72+
"functions": [
73+
{
74+
"name": "LogReading",
75+
"operation": "http.myorg.io/ordersservices.json#logreading"
76+
},
77+
{
78+
"name": "ProduceReport",
79+
"operation": "http.myorg.io/ordersservices.json#produceReport"
80+
}
81+
]
82+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
id: roomreadings
2+
name: Room Temp and Humidity Workflow
3+
version: '1.0'
4+
execTimeout:
5+
interval: PT1H
6+
runBefore: GenerateReport
7+
keepActive: true
8+
states:
9+
- name: ConsumeReading
10+
type: event
11+
start: true
12+
onEvents:
13+
- eventRefs:
14+
- TemperatureEvent
15+
- HumidityEvent
16+
actions:
17+
- functionRef:
18+
refName: LogReading
19+
eventDataFilter:
20+
dataOutputPath: "$.readings"
21+
end: true
22+
- name: GenerateReport
23+
type: operation
24+
actions:
25+
- functionRef:
26+
refName: ProduceReport
27+
parameters:
28+
data: "$.readings"
29+
end:
30+
terminate: true
31+
events:
32+
- name: TemperatureEvent
33+
type: my.home.sensors
34+
source: "/home/rooms/+"
35+
correlation:
36+
- contextAttributeName: roomId
37+
- name: HumidityEvent
38+
type: my.home.sensors
39+
source: "/home/rooms/+"
40+
correlation:
41+
- contextAttributeName: roomId
42+
functions:
43+
- name: LogReading
44+
operation: http.myorg.io/ordersservices.json#logreading
45+
- name: ProduceReport
46+
operation: http.myorg.io/ordersservices.json#produceReport
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"id": "keepactiveexectimeout",
3+
"name": "Keep Active and Exec Timeout Test Workflow",
4+
"version": "1.0",
5+
"execTimeout": {
6+
"interval": "PT1H",
7+
"runBefore": "GenerateReport"
8+
},
9+
"keepActive": true,
10+
"states": [
11+
]
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
id: keepactiveexectimeout
2+
name: Keep Active and Exec Timeout Test Workflow
3+
version: '1.0'
4+
execTimeout:
5+
interval: PT1H
6+
runBefore: GenerateReport
7+
keepActive: true
8+
states: []

0 commit comments

Comments
 (0)