From fa5140396ff2ff96ae6131ce9220031727277689 Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Wed, 28 Aug 2024 14:36:36 +0200 Subject: [PATCH 1/2] Added a new `until` property to `any` event consumption strategies Signed-off-by: Charles d'Avernas --- dsl-reference.md | 3 +- examples/listen-to-any-until-condition.yaml | 11 ++++++ examples/listen-to-any-until-consumed.yaml | 20 ++++++++++ schema/workflow.yaml | 43 +++++++++++++++++---- 4 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 examples/listen-to-any-until-condition.yaml create mode 100644 examples/listen-to-any-until-consumed.yaml diff --git a/dsl-reference.md b/dsl-reference.md index 68b3346b..deac0e8c 100644 --- a/dsl-reference.md +++ b/dsl-reference.md @@ -1489,8 +1489,9 @@ Represents the configuration of an event consumption strategy. | Property | Type | Required | Description | |----------|:----:|:--------:|-------------| | all | [`eventFilter[]`](#event-filter) | `no` | Configures the workflow to wait for all defined events before resuming execution.
*Required if `any` and `one` have not been set.* | -| any | [`eventFilter[]`](#event-filter) | `no` | Configures the workflow to wait for any of the defined events before resuming execution.
*Required if `all` and `one` have not been set.* | +| any | [`eventFilter[]`](#event-filter) | `no` | Configures the workflow to wait for any of the defined events before resuming execution.
*Required if `all` and `one` have not been set.*
*If empty, listens to all incoming events, and requires `until` to be set.* | | one | [`eventFilter`](#event-filter) | `no` | Configures the workflow to wait for the defined event before resuming execution.
*Required if `all` and `any` have not been set.* | +| until | `string`
[`eventConsumptionStrategy`](#event-consumption-strategy) | `no` | Configures the [runtime expression](dsl.md#runtime-expressions) condition or the events that must be consumed to stop listening.
*Only applies if `any` has been set, otherwise ignored.* | ### Event Properties diff --git a/examples/listen-to-any-until-condition.yaml b/examples/listen-to-any-until-condition.yaml new file mode 100644 index 00000000..9d611f5b --- /dev/null +++ b/examples/listen-to-any-until-condition.yaml @@ -0,0 +1,11 @@ +document: + dsl: '1.0.0-alpha1' + namespace: test + name: listen-to-any + version: '0.1.0' +do: + - callDoctor: + listen: + to: + any: [] + until: ( . | length ) > 3 #wait until 3 events have been consumed \ No newline at end of file diff --git a/examples/listen-to-any-until-consumed.yaml b/examples/listen-to-any-until-consumed.yaml new file mode 100644 index 00000000..7c46cc13 --- /dev/null +++ b/examples/listen-to-any-until-consumed.yaml @@ -0,0 +1,20 @@ +document: + dsl: '1.0.0-alpha1' + namespace: test + name: listen-to-any + version: '0.1.0' +do: + - callDoctor: + listen: + to: + any: + - with: + type: com.fake-hospital.vitals.measurements.temperature + data: ${ .temperature > 38 } + - with: + type: com.fake-hospital.vitals.measurements.bpm + data: ${ .bpm < 60 or .bpm > 100 } + until: + one: + with: + type: com.fake-hospital.patient.checked-out \ No newline at end of file diff --git a/schema/workflow.yaml b/schema/workflow.yaml index 1b47ec76..aa989227 100644 --- a/schema/workflow.yaml +++ b/schema/workflow.yaml @@ -1196,14 +1196,41 @@ $defs: $ref: '#/$defs/eventFilter' required: [ all ] - title: AnyEventConsumptionStrategy - properties: - any: - type: array - title: AnyEventConsumptionStrategyConfiguration - description: A list containing any of the events to consume. - items: - $ref: '#/$defs/eventFilter' - required: [ any ] + oneOf: + - properties: + any: + type: array + title: AnyEventConsumptionStrategyConfiguration + description: A list containing any of the events to consume. + items: + $ref: '#/$defs/eventFilter' + minItems: 1 + until: + oneOf: + - type: string + title: AnyEventUntilCondition + description: A runtime expression condition evaluated after consuming an event and which determines whether or not to continue listening. + - $ref: '#/$defs/eventConsumptionStrategy' + title: AnyEventUntilConsumed + description: The strategy that defines the event(s) to consume to stop listening. + required: [ any ] + - properties: + any: + type: array + title: AnyEventConsumptionStrategyConfiguration + description: A list containing any of the events to consume. + items: + $ref: '#/$defs/eventFilter' + maxItems: 0 + until: + oneOf: + - type: string + title: AnyEventUntilCondition + description: A runtime expression condition evaluated after consuming an event and which determines whether or not to continue listening. + - $ref: '#/$defs/eventConsumptionStrategy' + title: AnyEventUntilConsumed + description: The strategy that defines the event(s) to consume to stop listening. + required: [ any, until ] - title: OneEventConsumptionStrategy properties: one: From cabc4217789c1fa3ac3bf1df643d0322175a7d7b Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Fri, 10 Jan 2025 11:13:04 +0100 Subject: [PATCH 2/2] Fix schema and add invalid examples Signed-off-by: Charles d'Avernas --- .../invalid/listen-any-empty-no-until.yaml | 10 ++++++++++ .../invalid/listen-any-until-any-until.yaml | 14 ++++++++++++++ schema/workflow.yaml | 18 ++++++++++++------ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 .ci/validation/test/fixtures/invalid/listen-any-empty-no-until.yaml create mode 100644 .ci/validation/test/fixtures/invalid/listen-any-until-any-until.yaml diff --git a/.ci/validation/test/fixtures/invalid/listen-any-empty-no-until.yaml b/.ci/validation/test/fixtures/invalid/listen-any-empty-no-until.yaml new file mode 100644 index 00000000..5c9aef15 --- /dev/null +++ b/.ci/validation/test/fixtures/invalid/listen-any-empty-no-until.yaml @@ -0,0 +1,10 @@ +document: + dsl: '1.0.0-alpha1' + namespace: test + name: listen-to-any + version: '0.1.0' +do: + - callDoctor: + listen: + to: + any: [] \ No newline at end of file diff --git a/.ci/validation/test/fixtures/invalid/listen-any-until-any-until.yaml b/.ci/validation/test/fixtures/invalid/listen-any-until-any-until.yaml new file mode 100644 index 00000000..c9f32f62 --- /dev/null +++ b/.ci/validation/test/fixtures/invalid/listen-any-until-any-until.yaml @@ -0,0 +1,14 @@ +document: + dsl: '1.0.0-alpha1' + namespace: test + name: listen-to-any + version: '0.1.0' +do: +do: + - callDoctor: + listen: + to: + any: [] + until: + any: [] + until: ${ ($context.events | length) == 3 } \ No newline at end of file diff --git a/schema/workflow.yaml b/schema/workflow.yaml index 7dd8634b..0b0d29db 100644 --- a/schema/workflow.yaml +++ b/schema/workflow.yaml @@ -1319,9 +1319,12 @@ $defs: - type: string title: AnyEventUntilCondition description: A runtime expression condition evaluated after consuming an event and which determines whether or not to continue listening. - - $ref: '#/$defs/eventConsumptionStrategy' - title: AnyEventUntilConsumed - description: The strategy that defines the event(s) to consume to stop listening. + - allOf: + - $ref: '#/$defs/eventConsumptionStrategy' + title: AnyEventUntilConsumed + description: The strategy that defines the event(s) to consume to stop listening. + - properties: + until: false required: [ any ] - properties: any: @@ -1336,9 +1339,12 @@ $defs: - type: string title: AnyEventUntilCondition description: A runtime expression condition evaluated after consuming an event and which determines whether or not to continue listening. - - $ref: '#/$defs/eventConsumptionStrategy' - title: AnyEventUntilConsumed - description: The strategy that defines the event(s) to consume to stop listening. + - allOf: + - $ref: '#/$defs/eventConsumptionStrategy' + title: AnyEventUntilConsumed + description: The strategy that defines the event(s) to consume to stop listening. + - properties: + until: false required: [ any, until ] - title: OneEventConsumptionStrategy properties: