Skip to content

Commit 4e03cdb

Browse files
Merge pull request #963 from neuroglia-io/fix-917-semantic-inconsistencies-listen-vs-emit
Fixed inconsistencies between `listen` and `emit`
2 parents 151392d + 0d0ef10 commit 4e03cdb

File tree

4 files changed

+99
-77
lines changed

4 files changed

+99
-77
lines changed

ctk/features/set.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Feature: Set Task
33
I want to ensure that set tasks can be executed within the workflow
44
So that my implementation conforms to the expected behavior
55

6-
# Tests emit tasks
6+
# Tests set tasks
77
Scenario: Set Task
88
Given a workflow with definition:
99
"""yaml

dsl-reference.md

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
+ [Shell](#shell-process)
2626
+ [Script](#script-process)
2727
+ [Workflow](#workflow-process)
28-
- [Switch](#switch)
2928
- [Set](#set)
29+
- [Switch](#switch)
3030
- [Try](#try)
3131
- [Wait](#wait)
3232
+ [Flow Directive](#flow-directive)
@@ -42,6 +42,7 @@
4242
- [Standard Error Types](#standard-error-types)
4343
+ [Event Consumption Strategy](#event-consumption-strategy)
4444
+ [Event Filter](#event-filter)
45+
+ [Event Properties](#event-properties)
4546
+ [Retry](#retry)
4647
+ [Input](#input)
4748
+ [Output](#output)
@@ -230,9 +231,9 @@ The Serverless Workflow DSL defines a list of [tasks](#task) that **must be** su
230231
- [Call](#call), used to call services and/or functions.
231232
- [Do](#do), used to define one or more subtasks to perform in sequence.
232233
- [Fork](#fork), used to define one or more subtasks to perform concurrently.
233-
- [Emit](#emit), used to emit [events](#event).
234+
- [Emit](#emit), used to emit [events](#event-properties).
234235
- [For](#for), used to iterate over a collection of items, and conditionally perform a task for each of them.
235-
- [Listen](#listen), used to listen for an [event](#event) or more.
236+
- [Listen](#listen), used to listen for an [event](#event-properties) or more.
236237
- [Raise](#raise), used to raise an [error](#error) and potentially fault the [workflow](#workflow).
237238
- [Run](#run), used to run a [container](#container-process), a [script](#script-process) , a [shell](#shell-process) command or even another [workflow](#workflow-process).
238239
- [Switch](#switch), used to dynamically select and execute one of multiple alternative paths based on specified conditions
@@ -369,7 +370,7 @@ The [HTTP Call](#http-call) enables workflows to interact with external services
369370
| Name | Type | Required | Description|
370371
|:--|:---:|:---:|:---|
371372
| method | `string` | `yes` | The HTTP request method. |
372-
| endpoint | [`endpoint`](#endpoint) | `yes` | An URI or an object that describes the HTTP endpoint to call. |
373+
| endpoint | `string`\|[`endpoint`](#endpoint) | `yes` | An URI or an object that describes the HTTP endpoint to call. |
373374
| headers | `map` | `no` | A name/value mapping of the HTTP headers to use, if any. |
374375
| body | `any` | `no` | The HTTP request body, if any. |
375376
| query | `map[string, any]` | `no` | A name/value mapping of the query parameters to use, if any. |
@@ -496,7 +497,7 @@ Allows workflows to publish events to event brokers or messaging systems, facili
496497

497498
| Name | Type | Required | Description |
498499
|:--|:---:|:---:|:---|
499-
| emit.event | [`event`](#event) | `yes` | Defines the event to emit. |
500+
| emit.event | [`eventProperties`](#event-properties) | `yes` | Defines the event to emit. |
500501

501502
##### Examples
502503

@@ -510,15 +511,16 @@ do:
510511
- emitEvent:
511512
emit:
512513
event:
513-
source: https://petstore.com
514-
type: com.petstore.order.placed.v1
515-
data:
516-
client:
517-
firstName: Cruella
518-
lastName: de Vil
519-
items:
520-
- breed: dalmatian
521-
quantity: 101
514+
with:
515+
source: https://petstore.com
516+
type: com.petstore.order.placed.v1
517+
data:
518+
client:
519+
firstName: Cruella
520+
lastName: de Vil
521+
items:
522+
- breed: dalmatian
523+
quantity: 101
522524
```
523525

524526
#### For
@@ -530,9 +532,9 @@ Allows workflows to iterate over a collection of items, executing a defined set
530532
| Name | Type | Required | Description|
531533
|:--|:---:|:---:|:---|
532534
| for.each | `string` | `no` | The name of the variable used to store the current item being enumerated.<br>Defaults to `item`. |
533-
| for.in | `string` | `yes` | A [runtime expression](./dsl.md/#runtime-expressions) used to get the collection to enumerate. |
535+
| for.in | `string` | `yes` | A [runtime expression](dsl.md#runtime-expressions) used to get the collection to enumerate. |
534536
| for.at | `string` | `no` | The name of the variable used to store the index of the current item being enumerated.<br>Defaults to `index`. |
535-
| while | `string` | `no` | A [runtime expression](./dsl.md/#runtime-expressions) that represents the condition, if any, that must be met for the iteration to continue. |
537+
| while | `string` | `no` | A [runtime expression](dsl.md#runtime-expressions) that represents the condition, if any, that must be met for the iteration to continue. |
536538
| do | [`task`](#task) | `yes` | The task to perform for each item in the collection. |
537539

538540
##### Examples
@@ -965,7 +967,7 @@ do:
965967

966968
##### Switch Case
967969

968-
Defines a switch case, encompassing of a condition for matching and an associated action to execute upon a match.
970+
Defines a switch case, encompassing a condition for matching and an associated action to execute upon a match.
969971

970972
| Name | Type | Required | Description |
971973
|:--|:---:|:---:|:---|
@@ -1390,6 +1392,28 @@ Represents the configuration of an event consumption strategy.
13901392
| any | [`eventFilter[]`](#event-filter) | `no` | Configures the workflow to wait for any of the defined events before resuming execution.<br>*Required if `all` and `one` have not been set.* |
13911393
| one | [`eventFilter`](#event-filter) | `no` | Configures the workflow to wait for the defined event before resuming execution.<br>*Required if `all` and `any` have not been set.* |
13921394

1395+
### Event Properties
1396+
1397+
An event object typically includes details such as the event type, source, timestamp, and unique identifier along with any relevant data payload. The [Cloud Events specification](https://cloudevents.io/), favored by Serverless Workflow, standardizes this structure to ensure interoperability across different systems and services.
1398+
1399+
#### Properties
1400+
1401+
| Property | Type | Required | Description |
1402+
|----------|:----:|:--------:|-------------|
1403+
| id | `string` | `no` | Identifies the event. `source` + `id` is unique for each distinct event.<br>*Required when emitting an event using `emit.event.with`.* |
1404+
| source | `string` | `no` | An URI formatted string, or [runtime expression](dsl.md#runtime-expressions), that identifies the context in which an event happened. `source` + `id` is unique for each distinct event.<br>*Required when emitting an event using `emit.event.with`.* |
1405+
| type | `string` | `no` | Describes the type of event related to the originating occurrence.<br>*Required when emitting an event using `emit.event.with`.* |
1406+
| time | `string` | `no` | A string, or [runtime expression](dsl.md#runtime-expressions), representing the timestamp of when the occurrence happened. |
1407+
| subject | `string` | `no` | Describes the subject of the event in the context of the event producer. |
1408+
| datacontenttype | `string` | `no` | Content type of `data` value. If omitted, it implies the `data` is a JSON value conforming to the "application/json" media type. |
1409+
| dataschema | `string` | `no` | An URI formatted string, or [runtime expression](dsl.md#runtime-expressions), that identifies the schema that `data` adheres to. |
1410+
| data | `object` | `no` | The event payload. |
1411+
1412+
*Additional properties can be supplied, see the Cloud Events specification [documentation](https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#extension-context-attributes) for more info.*
1413+
1414+
*When used in an [`eventFilter`](#event-filter), at least one property must be supplied.*
1415+
1416+
13931417
### Event Filter
13941418

13951419
An event filter is a mechanism used to selectively process or handle events based on predefined criteria, such as event type, source, or specific attributes.
@@ -1398,7 +1422,7 @@ An event filter is a mechanism used to selectively process or handle events base
13981422

13991423
| Property | Type | Required | Description |
14001424
|----------|:----:|:--------:|-------------|
1401-
| with | `object` | `yes` | A name/value mapping of the attributes filtered events must define. Supports both regular expressions and runtime expressions. |
1425+
| with | [`eventProperties`](#event-properties) | `yes` | A name/value mapping of the attributes filtered events must define. Supports both regular expressions and runtime expressions. |
14021426
| correlate | [`map[string, correlation]`](#correlation) | `no` | A name/definition mapping of the correlations to attempt when filtering events. |
14031427

14041428
### Correlation
@@ -1474,7 +1498,7 @@ When set, runtimes must validate input data against the defined schema, unless d
14741498
| Property | Type | Required | Description |
14751499
|----------|:----:|:--------:|-------------|
14761500
| schema | [`schema`](#schema) | `no` | The [`schema`](#schema) used to describe and validate input data.<br>*Even though the schema is not required, it is strongly encouraged to document it, whenever feasible.* |
1477-
| from | `string`<br>`object` | `no` | A [runtime expression](#runtime-expressions), if any, used to filter and/or mutate the workflow/task input. |
1501+
| from | `string`<br>`object` | `no` | A [runtime expression](dsl.md#runtime-expressions), if any, used to filter and/or mutate the workflow/task input. |
14781502

14791503
#### Examples
14801504

@@ -1503,7 +1527,7 @@ When set, runtimes must validate output data against the defined schema, unless
15031527
| Property | Type | Required | Description |
15041528
|----------|:----:|:--------:|-------------|
15051529
| schema | [`schema`](#schema) | `no` | The [`schema`](#schema) used to describe and validate output data.<br>*Even though the schema is not required, it is strongly encouraged to document it, whenever feasible.* |
1506-
| as | `string`<br>`object` | `no` | A [runtime expression](#runtime-expressions), if any, used to filter and/or mutate the workflow/task output. |
1530+
| as | `string`<br>`object` | `no` | A [runtime expression](dsl.md#runtime-expressions), if any, used to filter and/or mutate the workflow/task output. |
15071531

15081532
#### Examples
15091533

@@ -1637,6 +1661,17 @@ minutes: 15
16371661
seconds: 30
16381662
```
16391663

1664+
### Endpoint
1665+
1666+
Describes an enpoint.
1667+
1668+
#### Properties
1669+
1670+
| Property | Type | Required | Description |
1671+
|----------|:----:|:--------:|-------------|
1672+
| uri | `string` | `yes` | The endpoint's URI. |
1673+
| authentication | `[authentication](#authentication)` | `no` | The authentication policy to use. |
1674+
16401675
### HTTP Response
16411676

16421677
Describes an HTTP response.

dsl.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Workflows in the Serverless Workflow DSL can exist in several phases, each indic
8181

8282
Additionally, the flow of execution within a workflow can be controlled using [directives*](dsl-reference.md#flow-directive), which provide instructions to the workflow engine on how to manage and handle specific aspects of workflow execution.
8383

84-
**To learn more about flow directives and how they can be utilized to control the execution and behavior of workflows, please refer to [Flow Directives](dsl-reference.md#flow-directive).*
84+
\**To learn more about flow directives and how they can be utilized to control the execution and behavior of workflows, please refer to [Flow Directives](dsl-reference.md#flow-directive).*
8585

8686
#### Components
8787

@@ -102,14 +102,14 @@ The Serverless Workflow DSL defines several default [task](dsl-reference.md#task
102102

103103
- [Call](dsl-reference.md#call), used to call services and/or functions.
104104
- [Do](dsl-reference.md#do), used to define one or more subtasks to perform in sequence.
105-
- [Fork](dsl-reference.md#fork), used to define one or more two subtasks to perform in parallel.
106105
- [Emit](dsl-reference.md#emit), used to emit [events](dsl-reference.md#event).
107106
- [For](dsl-reference.md#for), used to iterate over a collection of items, and conditionally perform a task for each of them.
107+
- [Fork](dsl-reference.md#fork), used to define one or more two subtasks to perform in parallel.
108108
- [Listen](dsl-reference.md#listen), used to listen for an [event](dsl-reference.md#event) or more.
109109
- [Raise](dsl-reference.md#raise), used to raise an [error](dsl-reference.md#error) and potentially fault the [workflow](dsl-reference.md#workflow).
110110
- [Run](dsl-reference.md#run), used to run a [container](dsl-reference.md#container-process), a [script](dsl-reference.md#script-process), a [shell](dsl-reference.md#shell-process) command or even another [workflow](dsl-reference.md#workflow-process).
111-
- [Switch](dsl-reference.md#switch), used to dynamically select and execute one of multiple alternative paths based on specified conditions
112111
- [Set](dsl-reference.md#set), used to dynamically set or update the [workflow](dsl-reference.md#workflow)'s data during the its execution.
112+
- [Switch](dsl-reference.md#switch), used to dynamically select and execute one of multiple alternative paths based on specified conditions
113113
- [Try](dsl-reference.md#try), used to attempt executing a specified [task](dsl-reference.md#task), and to handle any resulting [errors](dsl-reference.md#error) gracefully, allowing the [workflow](dsl-reference.md#workflow) to continue without interruption.
114114
- [Wait](dsl-reference.md#wait), used to pause or wait for a specified duration before proceeding to the next task.
115115

@@ -138,7 +138,7 @@ A workflow begins with the first task defined.
138138

139139
Once the task has been executed, different things can happen:
140140

141-
- `continue`: the task ran to completion, and the next task, if any, should be executed. The task to run next is implictly the next in declaration order, or explicitly defined by the `then` property of the executed task. If the executed task is the last task, then the workflow's execution gracefully ends.
141+
- `continue`: the task ran to completion, and the next task, if any, should be executed. The task to run next is implicitly the next in declaration order, or explicitly defined by the `then` property of the executed task. If the executed task is the last task, then the workflow's execution gracefully ends.
142142
- `fault`: the task raised an uncaught error, which abruptly halts the workflow's execution and makes it transition to `faulted` [status phase](#status-phases).
143143
- `end`: the task explicitly and gracefully ends the workflow's execution.
144144

schema/workflow.yaml

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
$id: https://serverlessworkflow.io/schemas/1.0.0-alpha1/workflow.yaml
23
$schema: https://json-schema.org/draft/2020-12/schema
34
description: Serverless Workflow DSL - Workflow Schema
@@ -369,37 +370,9 @@ $defs:
369370
event:
370371
type: object
371372
properties:
372-
id:
373-
type: string
374-
description: The event's unique identifier
375-
source:
376-
description: Identifies the context in which an event happened
377-
oneOf:
378-
- title: LiteralSource
379-
type: string
380-
format: uri-template
381-
- $ref: '#/$defs/runtimeExpression'
382-
type:
383-
type: string
384-
description: This attribute contains a value describing the type of event related to the originating occurrence.
385-
time:
386-
oneOf:
387-
- title: LiteralTime
388-
type: string
389-
format: date-time
390-
- $ref: '#/$defs/runtimeExpression'
391-
subject:
392-
type: string
393-
datacontenttype:
394-
type: string
395-
description: Content type of data value. This attribute enables data to carry any type of content, whereby format and encoding might differ from that of the chosen event format.
396-
dataschema:
397-
oneOf:
398-
- title: LiteralDataSchema
399-
type: string
400-
format: uri-template
401-
- $ref: '#/$defs/runtimeExpression'
402-
required: [ source, type ]
373+
with:
374+
$ref: '#/$defs/eventProperties'
375+
required: [ source, type ]
403376
additionalProperties: true
404377
required: [ event ]
405378
forTask:
@@ -852,6 +825,40 @@ $defs:
852825
$ref: '#/$defs/referenceableAuthenticationPolicy'
853826
description: The authentication policy to use.
854827
required: [ uri ]
828+
eventProperties:
829+
type: object
830+
properties:
831+
id:
832+
type: string
833+
description: The event's unique identifier
834+
source:
835+
description: Identifies the context in which an event happened
836+
oneOf:
837+
- title: LiteralSource
838+
type: string
839+
format: uri-template
840+
- $ref: '#/$defs/runtimeExpression'
841+
type:
842+
type: string
843+
description: This attribute contains a value describing the type of event related to the originating occurrence.
844+
time:
845+
oneOf:
846+
- title: LiteralTime
847+
type: string
848+
format: date-time
849+
- $ref: '#/$defs/runtimeExpression'
850+
subject:
851+
type: string
852+
datacontenttype:
853+
type: string
854+
description: Content type of data value. This attribute enables data to carry any type of content, whereby format and encoding might differ from that of the chosen event format.
855+
dataschema:
856+
oneOf:
857+
- title: LiteralDataSchema
858+
type: string
859+
format: uri-template
860+
- $ref: '#/$defs/runtimeExpression'
861+
additionalProperties: true
855862
eventConsumptionStrategy:
856863
type: object
857864
unevaluatedProperties: false
@@ -884,28 +891,8 @@ $defs:
884891
properties:
885892
with:
886893
title: WithEvent
887-
type: object
894+
$ref: '#/$defs/eventProperties'
888895
minProperties: 1
889-
properties:
890-
id:
891-
type: string
892-
description: The event's unique identifier
893-
source:
894-
type: string
895-
description: Identifies the context in which an event happened
896-
type:
897-
type: string
898-
description: This attribute contains a value describing the type of event related to the originating occurrence.
899-
time:
900-
type: string
901-
subject:
902-
type: string
903-
datacontenttype:
904-
type: string
905-
description: Content type of data value. This attribute enables data to carry any type of content, whereby format and encoding might differ from that of the chosen event format.
906-
dataschema:
907-
type: string
908-
additionalProperties: true
909896
description: An event filter is a mechanism used to selectively process or handle events based on predefined criteria, such as event type, source, or specific attributes.
910897
correlate:
911898
type: object

0 commit comments

Comments
 (0)