Skip to content

Commit 9021bd7

Browse files
committed
[Fix #677] Atomic produce and consume actions
Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
1 parent 3b6f976 commit 9021bd7

File tree

3 files changed

+105
-50
lines changed

3 files changed

+105
-50
lines changed

examples/event-based-service-invocation.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@
2626
"actions": [
2727
{
2828
"name": "make-appointment-action",
29-
"eventRef": {
30-
"produceEventRef": "make-vet-appointment",
31-
"data": "${ .patientInfo }",
32-
"consumeEventRef": "vet-appointment-info"
29+
"produceEventRef": {
30+
"name": "make-vet-appointment",
31+
"data": "${ .patientInfo }"
32+
}
33+
},
34+
{
35+
"name": "wait-appointement-confirmation",
36+
"consumeEventRef": {
37+
"name": "vet-appointment-info"
3338
},
3439
"actionDataFilter": {
3540
"results": "${ .appointmentInfo }"

schema/workflow.json

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,13 @@
413413
"description": "References a function to be invoked",
414414
"$ref": "#/definitions/functionref"
415415
},
416-
"eventRef": {
417-
"description": "References a `produce` and `consume` reusable event definitions",
418-
"$ref": "#/definitions/eventref"
416+
"produceEventRef": {
417+
"description": "References a `produce` reusable event definition",
418+
"$ref": "#/definitions/produceeventref"
419+
},
420+
"consumeEventRef": {
421+
"description": "References a `consume` reusable event definition",
422+
"$ref": "#/definitions/consumeeventref"
419423
},
420424
"subFlowRef": {
421425
"description": "References a sub-workflow to invoke",
@@ -468,7 +472,13 @@
468472
{
469473
"required": [
470474
"name",
471-
"eventRef"
475+
"produceEventRef"
476+
]
477+
},
478+
{
479+
"required": [
480+
"name",
481+
"consumeEventRef"
472482
]
473483
},
474484
{
@@ -521,24 +531,15 @@
521531
}
522532
]
523533
},
524-
"eventref": {
534+
"produceeventref": {
525535
"type": "object",
526-
"description": "Event References",
536+
"description": "Publish an event",
527537
"properties": {
528-
"produceEventRef": {
538+
"name": {
529539
"type": "string",
530540
"description": "Reference to the unique name of a 'produced' event definition",
531541
"pattern": "^[a-z0-9](-?[a-z0-9])*$"
532542
},
533-
"consumeEventRef": {
534-
"type": "string",
535-
"description": "Reference to the unique name of a 'consumed' event definition",
536-
"pattern": "^[a-z0-9](-?[a-z0-9])*$"
537-
},
538-
"consumeEventTimeout": {
539-
"type": "string",
540-
"description": "Maximum amount of time (ISO 8601 format) to wait for the result event. If not defined it should default to the actionExecutionTimeout"
541-
},
542543
"data": {
543544
"type": [
544545
"string",
@@ -556,7 +557,26 @@
556557
},
557558
"additionalProperties": false,
558559
"required": [
559-
"produceEventRef"
560+
"name", "data"
561+
]
562+
},
563+
"consumeeventref": {
564+
"type": "object",
565+
"description": "Waits for an event",
566+
"properties": {
567+
"name": {
568+
"type": "string",
569+
"description": "Reference to the unique name of a 'consumed' event definition",
570+
"pattern": "^[a-z0-9](-?[a-z0-9])*$"
571+
},
572+
"consumeEventTimeout": {
573+
"type": "string",
574+
"description": "Maximum amount of time (ISO 8601 format) to wait for the result event. If not defined it should default to the actionExecutionTimeout"
575+
}
576+
},
577+
"additionalProperties": false,
578+
"required": [
579+
"name"
560580
]
561581
},
562582
"subflowref": {
@@ -1690,7 +1710,7 @@
16901710
"name",
16911711
"type",
16921712
"action",
1693-
"eventRef"
1713+
""
16941714
]
16951715
},
16961716
"else": {

specification.md

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,7 +3987,8 @@ Actions specify invocations of services or other workflows during workflow execu
39873987
Service invocation can be done in three different ways:
39883988

39893989
* Reference [functions definitions](#Function-Definition) by its unique name using the `functionRef` property.
3990-
* Reference a `produced` and `consumed` [event definitions](#Event-Definition) via the `eventRef` property.
3990+
* Reference a `produced` [event definitions](#Event-Definition) via the `produceEventRef` property.
3991+
* Reference a `consumer` [event definitions](#Event-Definition) via the `consumeEventRef` property.
39913992
* Reference a sub-workflow invocation via the `subFlowRef` property.
39923993

39933994
Note that `functionRef`, `eventRef`, and `subFlowRef` are mutually exclusive, meaning that only one of them can be
@@ -3997,8 +3998,7 @@ The `name` property specifies the action name.
39973998

39983999
In the event-based scenario a service, or a set of services we want to invoke
39994000
are not exposed via a specific resource URI for example, but can only be invoked via an event.
4000-
The [eventRef](#EventRef-Definition) property defines the
4001-
referenced `produced` event via its `produceEventRef` property and a `consumed` event via its `consumeEventRef` property.
4001+
In that case, a `produced` event might be referenced via its `produceEventRef` property and a `consumed` event via its `consumeEventRef` property.
40024002

40034003
The `sleep` property can be used to define time periods that workflow execution should sleep
40044004
before and/or after function execution. It can have two properties:
@@ -4125,18 +4125,15 @@ In addition, functions that are invoked async do not propagate their errors to t
41254125
workflow state, meaning that any errors that happen during their execution cannot be handled in the workflow states
41264126
onErrors definition. Note that errors raised during functions that are invoked async should not fail workflow execution.
41274127

4128-
##### EventRef Definition
4128+
##### ProduceEventRef Definition
41294129

4130-
Allows defining invocation of a function via event.
4130+
Publish an event. It references the unique name of a `produced` event definition. Must follow the [Serverless Workflow Naming Convention](#naming-convention)
41314131

41324132
| Parameter | Description | Type | Required |
41334133
| --- | --- | --- | --- |
4134-
| [produceEventRef](#Event-Definition) | Reference to the unique name of a `produced` event definition. Must follow the [Serverless Workflow Naming Convention](#naming-convention) | string | yes |
4135-
| [consumeEventRef](#Event-Definition) | Reference to the unique name of a `consumed` event definition. Must follow the [Serverless Workflow Naming Convention](#naming-convention) | string | no |
4136-
| consumeEventTimeout | Maximum amount of time (ISO 8601 format literal or expression) to wait for the consume event. If not defined it be set to the [actionExecutionTimeout](#Workflow-Timeout-Definition) | string | no |
4137-
| data | If string type, an expression which selects parts of the states data output to become the data (payload) of the event referenced by `produceEventRef`. If object type, a custom object to become the data (payload) of the event referenced by `produceEventRef`. | string or object | no |
4134+
| [name](#Event-Definition) | Reference to the unique name of a `produced` event definition. Must follow the [Serverless Workflow Naming Convention](#naming-convention) | string | yes |
4135+
| data | If string type, an expression which selects parts of the states data output to become the data (payload) of the event referenced by `produceEventRef`. If object type, a custom object to become the data (payload) of the event referenced by `produceEventRef`. | string or object | yes |
41384136
| contextAttributes | Add additional event extension context attributes to the trigger/produced event | object | no |
4139-
| invoke | Specifies if the function should be invoked sync or async. Default is sync | enum | no |
41404137

41414138
<details><summary><strong>Click to view example definition</strong></summary>
41424139
<p>
@@ -4151,10 +4148,9 @@ Allows defining invocation of a function via event.
41514148

41524149
```json
41534150
{
4154-
"eventRef": {
4155-
"produceEventRef": "make-vet-appointment",
4151+
"produceEventRef": {
4152+
"name": "make-vet-appointment",
41564153
"data": "${ .patientInfo }",
4157-
"consumeEventRef": "vet-appointment-info"
41584154
}
41594155
}
41604156
```
@@ -4163,10 +4159,9 @@ Allows defining invocation of a function via event.
41634159
<td valign="top">
41644160

41654161
```yaml
4166-
eventRef:
4167-
produceEventRef: make-vet-appointment
4162+
produceEventRef:
4163+
name: make-vet-appointment
41684164
data: "${ .patientInfo }"
4169-
consumeEventRef: vet-appointment-info
41704165
```
41714166

41724167
</td>
@@ -4175,27 +4170,62 @@ eventRef:
41754170

41764171
</details>
41774172

4178-
References a `produced` and `consumed` [event definitions](#Event-Definition) via the `produceEventRef` and `consumeEventRef` properties, respectively.
4173+
References a `produced` [event definitions](#Event-Definition) via the `name` property.
41794174

41804175
The `data` property can have two types: string or object. If it is of string type, it is an expression that can select parts of state data
41814176
to be used as payload of the event referenced by `produceEventRef`. If it is of object type, you can define a custom object to be the event payload.
41824177

41834178
The `contextAttributes` property allows you to add one or more [extension context attributes](https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#extension-context-attributes)
41844179
to the trigger/produced event.
41854180

4181+
##### ConsumeEventRef Definition
4182+
4183+
Wait for an event to arrive.
4184+
4185+
| Parameter | Description | Type | Required |
4186+
| --- | --- | --- | --- |
4187+
| [name](#Event-Definition) | Reference to the unique name of a `consumed` event definition. Must follow the [Serverless Workflow Naming Convention](#naming-convention) | string | yes |
4188+
| consumeEventTimeout | Maximum amount of time (ISO 8601 format literal or expression) to wait for the consume event. If not defined it be set to the [actionExecutionTimeout](#Workflow-Timeout-Definition) | string | no |
4189+
4190+
<details><summary><strong>Click to view example definition</strong></summary>
4191+
<p>
4192+
4193+
<table>
4194+
<tr>
4195+
<th>JSON</th>
4196+
<th>YAML</th>
4197+
</tr>
4198+
<tr>
4199+
<td valign="top">
4200+
4201+
```json
4202+
{
4203+
"consumeEventRef": {
4204+
"name": "approved-appointment",
4205+
}
4206+
}
4207+
```
4208+
4209+
</td>
4210+
<td valign="top">
4211+
4212+
```yaml
4213+
eventRef:
4214+
consumeEventRef: approved-appointment
4215+
4216+
```
4217+
4218+
</td>
4219+
</tr>
4220+
</table>
4221+
4222+
</details>
4223+
4224+
References a `consumed` [event definitions](#Event-Definition) via the `name` property.
4225+
41864226
The `consumeEventTimeout` property defines the maximum amount of time (ISO 8601 format literal or expression) to wait for the result event. If not defined it should default to the [actionExecutionTimeout](#Workflow-Timeout-Definition).
4187-
If the event defined by the `consumeEventRef` property is not received in that set time, action invocation should raise an error
4188-
that can be handled in the states `onErrors` definition. In case the `consumeEventRef` is not defined, the `consumeEventTimeout` property is ignored.
4227+
If the event defined by the `name` property is not received in that set time, action invocation should raise an error that can be handled in the states `onErrors` definition.
41894228

4190-
The `invoke` property defines how the function is invoked (sync or async). Default value of this property is
4191-
`sync`, meaning that workflow execution should wait until the function completes (the result event is received).
4192-
If set to `async`, workflow execution should just produce the trigger event and should not wait for the result event.
4193-
Note that in this case the action does not produce any results (payload of the result event) and the associated actions eventDataFilter as well as
4194-
its retry definition, if defined, should be ignored.
4195-
Functions that are invoked via events (sync or async) do not propagate their errors to the associated action definition and the
4196-
workflow state, meaning that any errors that happen during their execution cannot be handled in the workflow states
4197-
onErrors definition. Note that errors raised during functions that are invoked sync or async in this case
4198-
should not fail workflow execution.
41994229

42004230
##### SubFlowRef Definition
42014231

0 commit comments

Comments
 (0)