generated from redhat-developer/new-project-template
-
Notifications
You must be signed in to change notification settings - Fork 55
RHIDP-9105: Best practices when creating a workflow #1424
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
Gerry-Forde
merged 10 commits into
redhat-developer:main
from
jmagak:RHIDP-9105-Best-practices-when-creating-a-workflow
Nov 5, 2025
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
04f0e0c
Update the best practices
invalid-email-address 5742ac3
Update the best practices
invalid-email-address 5ea6bc7
Update the best practices
invalid-email-address 0c0e7be
Merge branch 'main' into RHIDP-9105-Best-practices-when-creating-a-wo…
jmagak 58bf2fc
Apply suggestions
invalid-email-address 51aa4fe
Apply new suggestions
invalid-email-address cb1f001
Apply new suggestions
invalid-email-address 19945bd
Apply new suggestions
invalid-email-address 6d27ff6
Update new suggestions
invalid-email-address d9af45d
Merge branch 'main' into RHIDP-9105-Best-practices-when-creating-a-wo…
Gerry-Forde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
modules/orchestrator/ref-best-practices-for-creating-workflows.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| :_mod-docs-content-type: CONCEPT | ||
|
|
||
| [id="ref-best-practices-for-creating-workflows.adoc_{context}"] | ||
| = Best practices when creating serverless workflows | ||
|
|
||
| Create effective serverless workflows using thoughtful approaches to design, handle data, and manage error by following these best practices based on the Serverless Workflow Domain Specific Language (DSL) principles. These principles help you to build robust workflows. | ||
|
|
||
| Workflow design principles:: | ||
| + | ||
| The Serverless Workflow DSL prioritizes clarity and ease of use when writing workflows. | ||
|
|
||
| Priority of constituencies::: | ||
| + | ||
| When developing workflows or APIs, ensure the needs of the author (workflow writer) come first. The constituencies are prioritized in the following order: Authors > Operators > Implementors > Specifications writers. | ||
|
|
||
| Linguistic fluency and clarity::: | ||
| + | ||
| ** Use imperative verbs such as `Call`, `Emit`, `For`, `Fork`, `Raise`, `Run`, `Set`, `Switch`, and `Wait`. These simple, universally understood terms make your workflow simple to read and understand. | ||
|
|
||
| Structure and Extensibility::: | ||
jmagak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| + | ||
| ** Use implicit default behaviors to reduce redundancy. | ||
| ** Declare components inline if they are not reusable to keep the definition self-contained. | ||
| ** Use external references to import and reuse shared components, which promotes a modular design. | ||
| ** Prioritize flexibility over strict enumerations to ensure extensibility and adaptability across different runtime environments. | ||
|
|
||
| Data flow and runtime management:: | ||
| + | ||
| Controlling data flow is critical for efficient workflows. Tasks are the fundamental computing units of a workflow. The Domain Specific Language defines several default task types that runtimes must do. These include `Do`, `Listen`, `Raise`, `Run`, `Try`, and `Wait`. | ||
jmagak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| + | ||
| You can apply data transformations at several key points: | ||
|
|
||
| Workflow input validation::: Before the workflow starts, validate input data against the `input.schema` and use the top-level `input.from` expression to filter out data that is not relevant data to the workflow context. | ||
|
|
||
| Task Input/Output::: Before a task runs, transform its input using the `input.from` to match specific task requirements. After the task completes, use `output.as` runtime expression to transform its output before it is passed to the next task. | ||
jmagak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Context Management::: Use the `export.as` runtime expression to update the context of the workflow. This evaluates the transformed task output, making sure the final output is accurate and relevant. | ||
jmagak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Workflow output transformation::: Finally, transform the overall workflow output using `output.as` before returning it to the caller, making sure the final output is relevant. | ||
|
|
||
| Security and error handling:: | ||
| + | ||
| Secrets::: Use Secrets with caution. Use them within the `input.from` runtime expression to prevent them from being unintentionally exposed. Avoid passing them directly in expressions or call inputs as this might expose sensitive information. | ||
|
|
||
| Fault tolerance and error handling::: Serverless Workflow is designed with resilience in mind to recover from failures. | ||
| + | ||
| Standard Errors:::: Use _standard error types_, such as timeouts, to categorize errors consistently across different runtimes. These also facilitate seamless migration from one runtime environment to another. | ||
| Describe errors using the _Problem Details Request for Comments (RFC)_, with the `instance` property pointing to the component causing the error. | ||
|
|
||
| Retries:::: Use `try` blocks to implement retries for transient errors, such as a temporary network issue. | ||
jmagak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Timeouts:::: Configure timeouts for workflows and individual tasks. If a timeout occurs, you must interrupt the execution, and a standard timeout error with the type `https://serverlessworkflow.io/spec/0.8/errors/timeout` and status `408`is raised. | ||
jmagak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Orchestrator UI integration best practices:: | ||
| + | ||
| For your workflow results to be effectively displayed in the Orchestrator UI and to facilitate chaining of workflows, you must structure the output data according to the `WorkflowResult` schema. Additionally, include any error information as part of the workflow output so the UI and subsequent workflows can handle them accordingly. | ||
| + | ||
| Workflow output schema::: | ||
| + | ||
| Results placement:::: The primary output intended for subsequent processing should be placed under the `data.result` property. | ||
jmagak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Schema reference:::: Your output schema file (`schemas/workflow-output-schema.json`) should reference the `WorkflowResult` schema. | ||
jmagak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Outputs definition:::: Include an `outputs` section in your workflow definition. This section contains human-readable key/value pairs that the UI will display. | ||
| + | ||
| Structure of workflow: | ||
| + | ||
| [source,yaml] | ||
| ---- | ||
| id: my-workflow | ||
jmagak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| version: "0.8" | ||
| specVersion: "0.8" | ||
| name: My Workflow | ||
| start: ImmediatelyEnd | ||
| extensions: | ||
| - extensionid: workflow-output-schema | ||
| outputSchema: schemas/workflow-output-schema.json | ||
| states: | ||
| - name: ImmediatelyEnd | ||
| type: inject | ||
| data: | ||
| result: | ||
| message: A human-readable description of the successful status. Or an error. | ||
| outputs: | ||
| - key: Foo Bar human readable name which will be shown in the UI | ||
| value: Example string value produced on the output. This might be an input for a next workflow. | ||
| nextWorkflows: | ||
| - id: my-next-workflow-id | ||
| name: Next workflow name suggested if this is an assessment workflow. Human readable, it's text does not need to match true workflow name. | ||
jmagak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end: true | ||
| ---- | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.