Skip to content

Commit 7539516

Browse files
authored
Merge pull request serverlessworkflow#988 from neuroglia-io/feat-add-use-cases
Add use cases and examples
2 parents eb050fd + c652af6 commit 7539516

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1286
-30
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ It is a member project of the [CNCF Serverless Working Group](https://github.com
109109
## Documentation
110110

111111
The documentation for Serverless Workflow includes:
112+
112113
- [**DSL**](dsl.md): Documents the fundamentals aspects and concepts of the Serverless Workflow DSL
113114
- [**DSL Reference**](dsl-reference.md): References all the definitions used by the Serverless Workflow DSL
115+
- [**Examples**](./examples/README.md): A collection of practical examples demonstrating specific features and functionalities of Serverless Workflow.
116+
- [**Use Cases**](./use-cases/README.md): Detailed use cases illustrating how Serverless Workflow can be applied in various real-world scenarios.
114117

115118
## Community
116119

dsl-reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ Defines the [Problem Details RFC](https://datatracker.ietf.org/doc/html/rfc7807)
14511451
|----------|:----:|:--------:|-------------|
14521452
| type | [`uri-template`](#uri-template) | `yes` | A URI reference that identifies the [`error`](#error) type. <br><u>For cross-compatibility concerns, it is strongly recommended to use [Standard Error Types](#standard-error-types) whenever possible.<u><br><u>Runtimes **MUST** ensure that the property has been set when raising or escalating the [`error`](#error).<u> |
14531453
| status | `integer` | `yes` | The status code generated by the origin for this occurrence of the [`error`](#error).<br><u>For cross-compatibility concerns, it is strongly recommended to use [HTTP Status Codes](https://datatracker.ietf.org/doc/html/rfc7231#section-6) whenever possible.<u><br><u>Runtimes **MUST** ensure that the property has been set when raising or escalating the [`error`](#error).<u> |
1454-
| instance | `string` | `yes` | A [JSON Pointer](https://datatracker.ietf.org/doc/html/rfc6901) used to reference the component the [`error`](#error) originates from.<br><u>Runtimes **MUST** set the property when raising or escalating the [`error`](#error). Otherwise ignore.<u> |
1454+
| instance | `string` | `no` | A [JSON Pointer](https://datatracker.ietf.org/doc/html/rfc6901) used to reference the component the [`error`](#error) originates from.<br><u>Runtimes **MUST** set the property when raising or escalating the [`error`](#error). Otherwise ignore.<u> |
14551455
| title | `string` | `no` | A short, human-readable summary of the [`error`](#error). |
14561456
| detail | `string` | `no` | A human-readable explanation specific to this occurrence of the [`error`](#error). |
14571457

examples/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Examples
2+
3+
Welcome to the Serverless Workflow Examples directory! This section contains a collection of brief YAML files, each representing a single workflow definition.
4+
5+
These examples are designed to demonstrate specific features and functionalities of the Serverless Workflow DSL. They serve as a practical reference to help you understand and implement different aspects of Serverless Workflows in your projects.
6+
7+
## Contributing
8+
9+
We welcome contributions! If you have an example demonstrating a unique feature or use case of Serverless Workflow, feel free to submit a pull request.
10+
11+
For more detailed information on contributing, including guidelines and best practices, please refer to our [Contributing Guide](./CONTRIBUTING.md).

examples/bearer-auth-uri-format.yaml renamed to examples/authentication-bearer.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ do:
1212
uri: https://petstore.swagger.io/v2/pet/1
1313
authentication:
1414
bearer:
15-
token: ${ .token }
15+
token: ${ .token }
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
document:
2+
dsl: '1.0.0'
3+
namespace: samples
4+
name: call-custom-function-cataloged
5+
version: '1.0.0'
6+
do:
7+
- log:
8+
call: https://raw.githubusercontent.com/serverlessworkflow/catalog/main/functions/log/1.0.0/function.yaml
9+
with:
10+
message: Hello, world!
11+
level: information
12+
timestamp: true
13+
format: '{TIMESTAMP} [{LEVEL}] ({CONTEXT}): {MESSAGE}'
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
document:
2+
dsl: '1.0.0'
3+
namespace: samples
4+
name: call-custom-function-inline
5+
version: '1.0.0'
6+
use:
7+
functions:
8+
getPetById:
9+
input:
10+
schema:
11+
document:
12+
type: object
13+
properties:
14+
petId:
15+
type: string
16+
required: [ petId ]
17+
call: http
18+
with:
19+
method: get
20+
endpoint: https://petstore.swagger.io/v2/pet/{petId}
21+
do:
22+
- getPet:
23+
call: getPetById
24+
with:
25+
petId: 69

examples/call-grpc.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: grpc-example
5+
version: '0.1.0'
6+
do:
7+
- greet:
8+
call: grpc
9+
with:
10+
proto:
11+
endpoint: file://app/greet.proto
12+
service:
13+
name: GreeterApi.Greeter
14+
host: localhost
15+
port: 5011
16+
method: SayHello
17+
arguments:
18+
name: ${ .user.preferredDisplayName }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
document:
2+
dsl: 1.0.0-alpha1
3+
namespace: examples
4+
name: call-http-shorthand-endpoint
5+
version: 1.0.0-alpha1
6+
do:
7+
- getPet:
8+
call: http
9+
with:
10+
method: get
11+
endpoint: ${ "https://petstore.swagger.io/v2/pet/\(.petId)" }

examples/call-openapi.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: openapi-example
5+
version: '0.1.0'
6+
do:
7+
- findPet:
8+
call: openapi
9+
with:
10+
document:
11+
endpoint: https://petstore.swagger.io/v2/swagger.json
12+
operationId: findPetsByStatus
13+
parameters:
14+
status: available

examples/conditional-task.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
document:
2+
dsl: '1.0.0'
3+
namespace: default
4+
name: conditional-task
5+
version: '1.0.0'
6+
do:
7+
- raiseErrorIfUnderage:
8+
if: .customer.age < 18
9+
raise:
10+
error:
11+
type: https://superbet-casinos.com/customer/access-forbidden
12+
status: 400
13+
title: Access Forbidden
14+
then: end
15+
- placeBet:
16+
call: http
17+
with:
18+
method: post
19+
endpoint: https://superbet-casinos.com/api/bet/on/football
20+
body:
21+
customer: .customer
22+
bet: .bet

examples/do-multiple.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
document:
2+
dsl: 1.0.0-alpha1
3+
namespace: examples
4+
name: call-http-shorthand-endpoint
5+
version: 1.0.0-alpha1
6+
do:
7+
- getPet:
8+
call: http
9+
with:
10+
method: get
11+
endpoint: https://petstore.swagger.io/v2/pet/{petId}
12+
- buyPet:
13+
call: http
14+
with:
15+
method: put
16+
endpoint: https://petstore.swagger.io/v2/pet/{petId}
17+
body: '${ . + { status: "sold" } }'

examples/emit.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: emit
5+
version: '0.1.0'
6+
do:
7+
- emitEvent:
8+
emit:
9+
event:
10+
with:
11+
source: https://petstore.com
12+
type: com.petstore.order.placed.v1
13+
data:
14+
client:
15+
firstName: Cruella
16+
lastName: de Vil
17+
items:
18+
- breed: dalmatian
19+
quantity: 101

examples/for.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: for-example
5+
version: '0.1.0'
6+
do:
7+
- checkup:
8+
for:
9+
each: pet
10+
in: .pets
11+
at: index
12+
while: .vet != null
13+
do:
14+
- waitForCheckup:
15+
listen:
16+
to:
17+
one:
18+
with:
19+
type: com.fake.petclinic.pets.checkup.completed.v2
20+
output:
21+
as: '.pets + [{ "id": $pet.id }]'

examples/fork.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: fork-example
5+
version: '0.1.0'
6+
do:
7+
- raiseAlarm:
8+
fork:
9+
compete: true
10+
branches:
11+
- callNurse:
12+
call: http
13+
with:
14+
method: put
15+
endpoint: https://fake-hospital.com/api/v3/alert/nurses
16+
body:
17+
patientId: ${ .patient.fullName }
18+
room: ${ .room.number }
19+
- callDoctor:
20+
call: http
21+
with:
22+
method: put
23+
endpoint: https://fake-hospital.com/api/v3/alert/doctor
24+
body:
25+
patientId: ${ .patient.fullName }
26+
room: ${ .room.number }

examples/listen-to-all.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: listen-to-all
5+
version: '0.1.0'
6+
do:
7+
- callDoctor:
8+
listen:
9+
to:
10+
all:
11+
- with:
12+
type: com.fake-hospital.vitals.measurements.temperature
13+
data: ${ .temperature > 38 }
14+
- with:
15+
type: com.fake-hospital.vitals.measurements.bpm
16+
data: ${ .bpm < 60 or .bpm > 100 }

examples/listen-to-any.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: listen-to-any
5+
version: '0.1.0'
6+
do:
7+
- callDoctor:
8+
listen:
9+
to:
10+
any:
11+
- with:
12+
type: com.fake-hospital.vitals.measurements.temperature
13+
data: ${ .temperature > 38 }
14+
- with:
15+
type: com.fake-hospital.vitals.measurements.bpm
16+
data: ${ .bpm < 60 or .bpm > 100 }

examples/listen-to-one.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: listen-to-one
5+
version: '0.1.0'
6+
do:
7+
- waitForStartup:
8+
listen:
9+
to:
10+
one:
11+
with:
12+
type: com.virtual-wf-powered-race.events.race.started.v1
13+
- startup:
14+
call: http
15+
with:
16+
method: post
17+
endpoint:
18+
uri: https://virtual-wf-powered-race.com/api/v4/cars/{carId}/start

examples/raise.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: raise-not-implemented
5+
version: '0.1.0'
6+
do:
7+
- notImplemented:
8+
raise:
9+
error:
10+
type: https://serverlessworkflow.io/errors/not-implemented
11+
status: 500
12+
title: Not Implemented
13+
detail: ${ "The workflow '\( $workflow.definition.document.name ):\( $workflow.definition.document.version )' is a work in progress and cannot be run yet" }

examples/run-container.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: run-container
5+
version: '0.1.0'
6+
do:
7+
- runContainer:
8+
run:
9+
container:
10+
image: hello-world

examples/run-subflow.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: run-subflow
5+
version: '0.1.0'
6+
do:
7+
- registerCustomer:
8+
run:
9+
workflow:
10+
namespace: test
11+
name: register-customer
12+
version: '0.1.0'
13+
input:
14+
customer: .user
File renamed without changes.

examples/set.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
document:
2+
dsl: '1.0.0-alpha1'
3+
namespace: test
4+
name: set
5+
version: '0.1.0'
6+
schedule:
7+
on:
8+
one:
9+
with:
10+
type: io.serverlessworkflow.samples.events.trigger.v1
11+
do:
12+
- initialize:
13+
set:
14+
startEvent: ${ $workflow.input[0] }

examples/try-catch-retry.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
document:
2+
dsl: '1.0.0'
3+
namespace: default
4+
name: try-catch-retry
5+
version: '1.0.0'
6+
do:
7+
- tryGetPet:
8+
try:
9+
- getPet:
10+
call: http
11+
with:
12+
method: get
13+
endpoint: https://petstore.swagger.io/v2/pet/{petId}
14+
catch:
15+
errors:
16+
with:
17+
type: https://serverlessworkflow.io.io/dsl/errors/types/communication
18+
status: 503
19+
retry:
20+
delay:
21+
seconds: 3
22+
backoff:
23+
exponential: {}
24+
limit:
25+
attempt:
26+
count: 5

0 commit comments

Comments
 (0)