Skip to content

Commit 3b96c40

Browse files
authored
Merge pull request #118 from tsurdilo/addsleeptoactions
Add actions sleep
2 parents ae1d508 + 7004ffc commit 3b96c40

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed

api/src/main/resources/schema/actions/action.json

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"description": "References a sub-workflow to invoke",
2020
"$ref": "../functions/subflowref.json"
2121
},
22+
"sleep": {
23+
"$ref": "../sleep/sleep.json"
24+
},
2225
"actionDataFilter": {
2326
"$ref": "../filters/actiondatafilter.json"
2427
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"type": "object",
3+
"javaType": "io.serverlessworkflow.api.sleep.Sleep",
4+
"properties": {
5+
"before": {
6+
"type": "string",
7+
"description": "Amount of time (ISO 8601 duration format) to sleep before function/subflow invocation. Does not apply if 'eventRef' is defined."
8+
},
9+
"after": {
10+
"type": "string",
11+
"description": "Amount of time (ISO 8601 duration format) to sleep after function/subflow invocation. Does not apply if 'eventRef' is defined."
12+
}
13+
},
14+
"required": [
15+
"before",
16+
"after"
17+
]
18+
}

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

+43
Original file line numberDiff line numberDiff line change
@@ -657,4 +657,47 @@ public void testAuthOAuth(String workflowLocation) {
657657
assertEquals("${ $SECRETS.clientid }", auth.getOauth().getClientId());
658658
assertEquals("${ $SECRETS.clientsecret }", auth.getOauth().getClientSecret());
659659
}
660+
661+
@ParameterizedTest
662+
@ValueSource(strings = {"/features/actionssleep.json", "/features/actionssleep.yml"})
663+
public void testActionsSleep(String workflowLocation) {
664+
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
665+
666+
assertNotNull(workflow);
667+
assertNotNull(workflow.getId());
668+
assertNotNull(workflow.getName());
669+
assertNotNull(workflow.getStates());
670+
671+
assertNotNull(workflow.getStates());
672+
assertEquals(1, workflow.getStates().size());
673+
674+
State state = workflow.getStates().get(0);
675+
assertTrue(state instanceof OperationState);
676+
677+
OperationState operationState = (OperationState) workflow.getStates().get(0);
678+
assertNotNull(operationState.getActions());
679+
assertEquals(2, operationState.getActions().size());
680+
681+
Action action1 = operationState.getActions().get(0);
682+
assertNotNull(action1);
683+
assertNotNull(action1.getFunctionRef());
684+
assertNotNull(action1.getSleep());
685+
assertEquals("PT5S", action1.getSleep().getBefore());
686+
assertEquals("PT10S", action1.getSleep().getAfter());
687+
FunctionRef functionRef1 = action1.getFunctionRef();
688+
assertEquals("creditCheckFunction", functionRef1.getRefName());
689+
assertNull(functionRef1.getArguments());
690+
691+
Action action2 = operationState.getActions().get(1);
692+
assertNotNull(action2);
693+
assertNotNull(action2.getFunctionRef());
694+
assertNotNull(action2.getSleep());
695+
assertEquals("PT5S", action2.getSleep().getBefore());
696+
assertEquals("PT10S", action2.getSleep().getAfter());
697+
FunctionRef functionRef2 = action2.getFunctionRef();
698+
assertEquals("sendRejectionEmailFunction", functionRef2.getRefName());
699+
assertEquals(1, functionRef2.getArguments().size());
700+
assertEquals("${ .customer }", functionRef2.getArguments().get("applicant").asText());
701+
702+
}
660703
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "functionrefs",
3+
"version": "1.0",
4+
"specVersion": "0.7",
5+
"name": "Customer Credit Check Workflow",
6+
"description": "Perform Customer Credit Check",
7+
"start": "TestFunctionRef",
8+
"functions": [
9+
{
10+
"name": "creditCheckFunction",
11+
"operation": "http://myapis.org/creditcheckapi.json#doCreditCheck"
12+
},
13+
{
14+
"name": "sendRejectionEmailFunction",
15+
"operation": "http://myapis.org/creditcheckapi.json#rejectionEmail"
16+
}
17+
],
18+
"states": [
19+
{
20+
"name": "TestFunctionRefs",
21+
"type": "operation",
22+
"actionMode": "sequential",
23+
"actions": [
24+
{
25+
"functionRef": "creditCheckFunction",
26+
"sleep": {
27+
"before": "PT5S",
28+
"after": "PT10S"
29+
}
30+
},
31+
{
32+
"functionRef": {
33+
"refName": "sendRejectionEmailFunction",
34+
"arguments": {
35+
"applicant": "${ .customer }"
36+
}
37+
},
38+
"sleep": {
39+
"before": "PT5S",
40+
"after": "PT10S"
41+
}
42+
}
43+
],
44+
"end": true
45+
}
46+
]
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
id: functionrefs
2+
version: '1.0'
3+
specVersion: '0.7'
4+
name: Customer Credit Check Workflow
5+
description: Perform Customer Credit Check
6+
start: TestFunctionRef
7+
functions:
8+
- name: creditCheckFunction
9+
operation: http://myapis.org/creditcheckapi.json#doCreditCheck
10+
- name: sendRejectionEmailFunction
11+
operation: http://myapis.org/creditcheckapi.json#rejectionEmail
12+
states:
13+
- name: TestFunctionRefs
14+
type: operation
15+
actionMode: sequential
16+
actions:
17+
- functionRef: creditCheckFunction
18+
sleep:
19+
before: PT5S
20+
after: PT10S
21+
- functionRef:
22+
refName: sendRejectionEmailFunction
23+
arguments:
24+
applicant: "${ .customer }"
25+
sleep:
26+
before: PT5S
27+
after: PT10S
28+
end: true

0 commit comments

Comments
 (0)