Skip to content

Adding timeouts #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.serverlessworkflow.api.error.Error;
import io.serverlessworkflow.api.filters.StateDataFilter;
import io.serverlessworkflow.api.states.DefaultState.Type;
import io.serverlessworkflow.api.timeouts.TimeoutsDefinition;
import io.serverlessworkflow.api.transitions.Transition;

import java.util.List;
Expand All @@ -43,4 +44,6 @@ public interface State {
String getCompensatedBy();

Map<String, String> getMetadata();

TimeoutsDefinition getTimeouts();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.serverlessworkflow.api.states.DefaultState;
import io.serverlessworkflow.api.states.OperationState;
import io.serverlessworkflow.api.states.ParallelState;
import io.serverlessworkflow.api.timeouts.TimeoutsDefinition;
import io.serverlessworkflow.api.transitions.Transition;
import io.serverlessworkflow.api.workflow.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public void serialize(Workflow workflow,
workflow.getExpressionLang());
}

if (workflow.getExecTimeout() != null) {
gen.writeObjectField("execTimeout", workflow.getExecTimeout());
}

if (workflow.isKeepActive()) {
gen.writeBooleanField("keepActive", workflow.isKeepActive());
}
Expand Down Expand Up @@ -159,6 +155,10 @@ public void serialize(Workflow workflow,
gen.writeObjectField("constants", workflow.getConstants().getConstantsDef());
}

if(workflow.getTimeouts() != null ) {
gen.writeObjectField("timeouts", workflow.getTimeouts());
}

if (workflow.getStates() != null && !workflow.getStates().isEmpty()) {
gen.writeArrayFieldStart("states");
for (State state : workflow.getStates()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public class Constants {
private String refValue;
private JsonNode constantsDef;

public Constants() {}

public Constants(String refValue) {
this.refValue = refValue;
}

public Constants(JsonNode constantsDef) {
this.constantsDef = constantsDef;
}

public String getRefValue() {
return refValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public class Secrets {
private String refValue;
private List<String> secretDefs;

public Secrets() {}

public Secrets(String refValue) {
this.refValue = refValue;
}

public Secrets(List<String> secretDefs) {
this.secretDefs = secretDefs;
}

public String getRefValue() {
return refValue;
}
Expand Down
4 changes: 0 additions & 4 deletions api/src/main/resources/schema/actions/action.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
"description": "References a sub-workflow to invoke",
"$ref": "../functions/subflowref.json"
},
"timeout": {
"type": "string",
"description": "Time period to wait for function execution to complete"
},
"actionDataFilter": {
"$ref": "../filters/actiondatafilter.json"
}
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/resources/schema/branches/branch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"type": "object",
"$ref": "../actions/action.json"
}
},
"timeouts": {
"$ref": "../timeouts/timeoutsdef.json"
}
},
"oneOf": [
Expand Down
4 changes: 0 additions & 4 deletions api/src/main/resources/schema/states/callbackstate.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
"type" : "string",
"description": "References an unique callback event name in the defined workflow events"
},
"timeout": {
"type": "string",
"description": "Time period to wait for incoming events (ISO 8601 format)"
},
"eventDataFilter": {
"description": "Callback event data filter definition",
"$ref": "../filters/eventdatafilter.json"
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/resources/schema/states/defaultstate.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
"type": "string",
"minLength": 1,
"description": "Unique Name of a workflow state which is responsible for compensation of this state"
},
"timeouts": {
"$ref": "../timeouts/timeoutsdef.json"
}
},
"required": [
Expand Down
4 changes: 0 additions & 4 deletions api/src/main/resources/schema/states/eventstate.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
"type": "object",
"$ref": "../events/onevents.json"
}
},
"timeout": {
"type": "string",
"description": "Time period to wait for incoming events (ISO 8601 format)"
}
},
"required": [
Expand Down
4 changes: 0 additions & 4 deletions api/src/main/resources/schema/states/switchstate.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
"$ref": "../switchconditions/datacondition.json"
}
},
"eventTimeout": {
"type": "string",
"description": "If eventConditions is used, defines the time period to wait for events (ISO 8601 format)"
},
"defaultCondition": {
"description": "Default transition of the workflow if there is no matching data conditions. Can include a transition or end definition",
"$ref": "../defaultcondition/defaultconditiondef.json"
Expand Down
31 changes: 31 additions & 0 deletions api/src/main/resources/schema/timeouts/timeoutsdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"type": "object",
"javaType": "io.serverlessworkflow.api.timeouts.TimeoutsDefinition",
"description": "Timeouts Definition",
"properties": {
"workflowExecTimeout": {
"$ref": "workflowexectimeout.json"
},
"stateExecTimeout": {
"type": "string",
"description": "State execution timeout duration (ISO 8601 duration format)",
"minLength": 1
},
"actionExecTimeout": {
"type": "string",
"description": "Single actions definition execution timeout duration (ISO 8601 duration format)",
"minLength": 1
},
"branchExecTimeout": {
"type": "string",
"description": "Single branch execution timeout duration (ISO 8601 duration format)",
"minLength": 1
},
"eventTimeout": {
"type": "string",
"description": "Timeout duration to wait for consuming defined events (ISO 8601 duration format)",
"minLength": 1
}
},
"required": []
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"type": "object",
"javaType": "io.serverlessworkflow.api.exectimeout.ExecTimeout",
"javaType": "io.serverlessworkflow.api.timeouts.WorkflowExecTimeout",
"properties": {
"duration": {
"type": "string",
"description": "Timeout duration (ISO 8601 duration format)",
"description": "Workflow execution timeout duration (ISO 8601 duration format). If not specified should be 'unlimited'",
"minLength": 1
},
"interrupt": {
"type": "boolean",
"description": "If `false`, workflow instance is allowed to finish current execution. If `true`, current workflow execution is abrupted.",
"default": false
"default": true
},
"runBefore": {
"type": "string",
Expand Down
7 changes: 3 additions & 4 deletions api/src/main/resources/schema/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
"default": "jq",
"minLength": 1
},
"execTimeout": {
"description": "Workflow execution timeout",
"$ref": "exectimeout/exectimeout.json"
},
"keepActive": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -82,6 +78,9 @@
"existingJavaType": "io.serverlessworkflow.api.workflow.Constants",
"description": "Workflow constants definitions"
},
"timeouts": {
"$ref": "timeouts/timeoutsdef.json"
},
"states": {
"type": "array",
"description": "State Definitions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@
import com.fasterxml.jackson.databind.JsonNode;
import io.serverlessworkflow.api.Workflow;
import io.serverlessworkflow.api.actions.Action;
import io.serverlessworkflow.api.branches.Branch;
import io.serverlessworkflow.api.datainputschema.DataInputSchema;
import io.serverlessworkflow.api.defaultdef.DefaultConditionDefinition;
import io.serverlessworkflow.api.exectimeout.ExecTimeout;
import io.serverlessworkflow.api.functions.FunctionDefinition;
import io.serverlessworkflow.api.functions.FunctionRef;
import io.serverlessworkflow.api.functions.SubFlowRef;
import io.serverlessworkflow.api.interfaces.State;
import io.serverlessworkflow.api.retry.RetryDefinition;
import io.serverlessworkflow.api.states.EventState;
import io.serverlessworkflow.api.states.OperationState;
import io.serverlessworkflow.api.states.ParallelState;
import io.serverlessworkflow.api.states.SwitchState;
import io.serverlessworkflow.api.switchconditions.DataCondition;
import io.serverlessworkflow.api.test.utils.WorkflowTestUtils;
import io.serverlessworkflow.api.timeouts.WorkflowExecTimeout;
import io.serverlessworkflow.api.workflow.Constants;
import io.serverlessworkflow.api.workflow.Retries;
import io.serverlessworkflow.api.workflow.Secrets;
Expand Down Expand Up @@ -255,9 +257,10 @@ public void testKeepActiveExecTimeout(String workflowLocation) {
assertNotNull(workflow.getStates());

assertTrue(workflow.isKeepActive());
assertNotNull(workflow.getExecTimeout());
assertNotNull(workflow.getTimeouts());
assertNotNull(workflow.getTimeouts().getWorkflowExecTimeout());

ExecTimeout execTimeout = workflow.getExecTimeout();
WorkflowExecTimeout execTimeout = workflow.getTimeouts().getWorkflowExecTimeout();
assertEquals("PT1H", execTimeout.getDuration());
assertEquals("GenerateReport", execTimeout.getRunBefore());
}
Expand Down Expand Up @@ -545,4 +548,53 @@ public void testConstants(String workflowLocation) {
assertEquals("pas", serbianTranslationNode.asText());

}

@ParameterizedTest
@ValueSource(strings = {"/features/timeouts.json", "/features/timeouts.yml"})
public void testTimeouts(String workflowLocation) {
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));

assertNotNull(workflow);
assertNotNull(workflow.getId());
assertNotNull(workflow.getName());
assertNotNull(workflow.getStates());

assertNotNull(workflow.getTimeouts());
assertNotNull(workflow.getTimeouts().getWorkflowExecTimeout());

WorkflowExecTimeout execTimeout = workflow.getTimeouts().getWorkflowExecTimeout();
assertEquals("PT1H", execTimeout.getDuration());
assertEquals("GenerateReport", execTimeout.getRunBefore());

assertNotNull(workflow.getStates());
assertEquals(2, workflow.getStates().size());
assertTrue(workflow.getStates().get(0) instanceof EventState);

EventState firstState = (EventState) workflow.getStates().get(0);
assertNotNull(firstState.getTimeouts());
assertNotNull(firstState.getTimeouts().getStateExecTimeout());
assertNotNull(firstState.getTimeouts().getEventTimeout());
assertEquals("PT5M", firstState.getTimeouts().getStateExecTimeout());
assertEquals("PT2M", firstState.getTimeouts().getEventTimeout());


assertTrue(workflow.getStates().get(1) instanceof ParallelState);
ParallelState secondState = (ParallelState) workflow.getStates().get(1);
assertNotNull(secondState.getTimeouts());
assertNotNull(secondState.getTimeouts().getStateExecTimeout());
assertEquals("PT5M", secondState.getTimeouts().getStateExecTimeout());

assertNotNull(secondState.getBranches());
assertEquals(2, secondState.getBranches().size());
List<Branch> branches = secondState.getBranches();

assertNotNull(branches.get(0).getTimeouts());
assertNotNull(branches.get(0).getTimeouts().getBranchExecTimeout());
assertEquals("PT3S", branches.get(0).getTimeouts().getBranchExecTimeout());

assertNotNull(branches.get(1).getTimeouts());
assertNotNull(branches.get(1).getTimeouts().getBranchExecTimeout());
assertEquals("PT4S", branches.get(1).getTimeouts().getBranchExecTimeout());

}
}
4 changes: 3 additions & 1 deletion api/src/test/resources/examples/checkcarvitals.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
}
}
],
"timeout": "PT2M",
"timeouts": {
"eventTimeout": "PT2M"
},
"transition": "ShouldStopOrContinue"
},
{
Expand Down
3 changes: 2 additions & 1 deletion api/src/test/resources/examples/checkcarvitals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ states:
- StopVitalsCheck
eventDataFilter:
toStateData: "${ .stopReceived }"
timeout: PT2M
timeouts:
eventTimeout: PT2M
transition: ShouldStopOrContinue
- name: ShouldStopOrContinue
type: switch
Expand Down
4 changes: 3 additions & 1 deletion api/src/test/resources/examples/creditcheck.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
}
},
"eventRef": "CreditCheckCompletedEvent",
"timeout": "PT15M",
"timeouts": {
"stateExecTimeout": "PT15M"
},
"transition": "EvaluateDecision"
},
{
Expand Down
3 changes: 2 additions & 1 deletion api/src/test/resources/examples/creditcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ states:
arguments:
customer: "${ .customer }"
eventRef: CreditCheckCompletedEvent
timeout: PT15M
timeouts:
stateExecTimeout: PT15M
transition: EvaluateDecision
- name: EvaluateDecision
type: switch
Expand Down
4 changes: 3 additions & 1 deletion api/src/test/resources/examples/eventbasedtransition.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"transition": "HandleRejectedVisa"
}
],
"eventTimeout": "PT1H",
"timeouts": {
"eventTimeout": "PT1H"
},
"defaultCondition": {
"transition": "HandleNoVisaDecision"
}
Expand Down
3 changes: 2 additions & 1 deletion api/src/test/resources/examples/eventbasedtransition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ states:
transition: HandleApprovedVisa
- eventRef: visaRejectedEvent
transition: HandleRejectedVisa
eventTimeout: PT1H
timeouts:
eventTimeout: PT1H
defaultCondition:
transition: HandleNoVisaDecision
- name: HandleApprovedVisa
Expand Down
8 changes: 5 additions & 3 deletions api/src/test/resources/examples/roomreadings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"version": "1.0",
"specVersion": "0.7",
"start": "ConsumeReading",
"execTimeout": {
"duration": "PT1H",
"runBefore": "GenerateReport"
"timeouts": {
"workflowExecTimeout": {
"duration": "PT1H",
"runBefore": "GenerateReport"
}
},
"keepActive": true,
"states": [
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy