Skip to main content

Step Definitions

Step Definitions are fundamental components within process definitions. They define the behavior, configuration, and relationships of each step in a process.

Overview

The StepDefinition class encapsulates the definition of a step within a process. It includes metadata about the step, its configuration, inputs, outputs, and its relationship with other steps. Understanding the structure and components of StepDefinition is essential for defining and managing process steps.

Fields

FieldTypeDescription
namespaceStringSame value as the process definition namespace.
nameStringThe name of the step, used for identification and referring to workers.
typeStepTypeThe type of the step, determining its behavior and execution logic.
refStringReference identifier for the step, allowing linkage to other steps for passing outputs as inputs.
optionalbooleanIndicates if the step is optional, meaning the process can continue even if this step fails.
createdByStringUsername or identifier of the user who defined the step.
updatedByStringUsername or identifier of the user who last updated the step.
createdlongEpoch timestamp marking when the step was created.
updatedlongEpoch timestamp marking when the step was last updated.
configurationStepConfigurationConfiguration settings specific to the step, defining its operational parameters.
childrenList<StepDefinition>List of child steps, allowing for nested or hierarchical step structures within the process.
inputMap<String, Object>Input data provided to the step, used during its execution.
outputMap<String, Object>Output data produced by the step after execution, which can be used by subsequent steps.

StepType

The StepType enum defines the various types of steps that can exist within a process. Each type determines the execution behavior and the nature of the step.

Step TypeDescription
HTTPExecutes HTTP or REST API requests, useful for interacting with external APIs or services.
WAITIntroduces a delay or pause in the process execution. You can wait for seconds, months, or years!
WORKERDelegates execution to a worker service or background job.
FAILIntentionally fails the step, useful for testing error handling and process termination.
PYTHONExecutes Python scripts or commands within the step.
JAVASCRIPTExecutes JavaScript code or scripts within the step.
JQUtilizes jq for processing and transforming JSON data within the step.
NOOPPerforms no operation, effectively acting as a placeholder within the process.
DEPENDSONSpecifies dependencies on other steps, ensuring certain steps are completed first.
INTEGRATIONIntegrates with external systems or services, facilitating seamless interoperability.
EXITTerminates the process execution, often used for cleanup or finalization tasks.
LISTContainer type that executes a list of steps sequentially.
PARALLELContainer type that executes multiple steps in parallel.
FOREACHContainer type that iterates over a collection, executing steps for each item.
SWITCHContainer type that branches execution based on specified conditions or criteria.

Step Configuration

FieldTypeDescription
errorPolicyNameStringDefines the policy to handle errors that occur during the step's execution. Check Error Policy for details
useCachebooleanIndicates whether the step should utilize caching mechanisms to store or retrieve data.
cacheKeyStringKey used to identify and retrieve cached data specific to the step.
cacheTimeoutSecondslongSpecifies the duration (in seconds) for which cached data remains valid.
skipStepbooleanDetermines if the step should be skipped during execution, regardless of other conditions.
skipReasonStringProvides a reason for why the step is being skipped, aiding in debugging and auditing.
jqTransformerStringDefines a jq transformation script for processing JSON data within the step.

Usage Examples

Example: Defining an HTTP Step

A step that performs an HTTP GET request to fetch data from an external API.

{
"namespace": "default",
"name": "getCustomerDetail",
"type": "HTTP",
"ref": "customerDetails",
"optional": false,
"configuration": {
"errorPolicyName": "retry_3_times_and_fail",
"useCache": true,
"cacheKey": "{{ context.input.customerEmail }} ",
"cacheTimeoutSeconds": 36000
},
"children": [],
"input": {
"method": "GET",
"url": "http://localhost:8080/api/test/get",
"headers": {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Bearer test"
},
"params": {
"customerEmail": "{{ context.input.customerEmail }} "
}
}
}

Best Practices

  • Consistent Naming: Use clear and descriptive names for steps to enhance readability and maintainability.
  • Modular Design: Break down complex processes into smaller, reusable steps to simplify debugging and testing.
  • Error Handling: Define appropriate errorPolicyName in StepConfiguration to manage failures gracefully.
  • Caching Strategy: Leverage caching by setting useCache and defining cacheKey to optimize performance for repetitive tasks.