Skip to content

Commit caa5139

Browse files
authored
Merge pull request #389 from serverlessworkflow/feat-emit-cloud-events
Updated the WorkflowExecutionContext to publish cloud events after handling each and every workflow and task operations
2 parents 2029499 + 58a9d96 commit caa5139

25 files changed

+1526
-5
lines changed

src/api/Synapse.Api.Server/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
}
2020
},
2121
"Events": {
22-
"Endpoint": "https://webhook.site/e2e48dd2-4ff5-477d-9788-f8fa9abdae7d"
22+
"Endpoint": "https://webhook.site/a4aff725-0711-48b2-a9d2-5d1b806d04d0"
2323
}
2424
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace System.ComponentModel.DataAnnotations;
15+
16+
/// <summary>
17+
/// Represents an <see cref="Attribute"/> used to set the attributes of a cloud event data type
18+
/// </summary>
19+
/// <param name="type">The cloud event type attribute </param>
20+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
21+
public class CloudEventAttribute(string type)
22+
: Attribute
23+
{
24+
25+
/// <summary>
26+
/// Gets the cloud event type attribute
27+
/// </summary>
28+
public virtual string Type { get; } = type;
29+
30+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace Synapse.Events.Tasks;
15+
16+
/// <summary>
17+
/// Represents the data carried by the cloud event that notifies that a task is being retried
18+
/// </summary>
19+
[CloudEvent(SynapseDefaults.CloudEvents.Task.Retrying.v1)]
20+
public record RetryingTaskEventV1
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the qualified name of the workflow instance the task that is being retried belongs to
25+
/// </summary>
26+
[DataMember(Name = "workflow", Order = 1), JsonPropertyName("workflow"), JsonPropertyOrder(1), YamlMember(Alias = "workflow", Order = 1)]
27+
public required string Workflow { get; set; }
28+
29+
/// <summary>
30+
/// Gets/sets the reference of the task that is being retried
31+
/// </summary>
32+
[DataMember(Name = "task", Order = 2), JsonPropertyName("task"), JsonPropertyOrder(2), YamlMember(Alias = "task", Order = 2)]
33+
public required Uri Task { get; set; }
34+
35+
/// <summary>
36+
/// Gets/sets the date and time at which the task is being retried
37+
/// </summary>
38+
[DataMember(Name = "retryingAt", Order = 3), JsonPropertyName("retryingAt"), JsonPropertyOrder(3), YamlMember(Alias = "retryingAt", Order = 3)]
39+
public DateTimeOffset RetryingAt { get; set; } = DateTimeOffset.Now;
40+
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace Synapse.Events.Tasks;
15+
16+
/// <summary>
17+
/// Represents the data carried by the cloud event that notifies that the execution of a task has been cancelled
18+
/// </summary>
19+
[CloudEvent(SynapseDefaults.CloudEvents.Task.Cancelled.v1)]
20+
public record TaskCancelledEventV1
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the qualified name of the workflow instance the task that has been cancelled belongs to
25+
/// </summary>
26+
[DataMember(Name = "workflow", Order = 1), JsonPropertyName("workflow"), JsonPropertyOrder(1), YamlMember(Alias = "workflow", Order = 1)]
27+
public required string Workflow { get; set; }
28+
29+
/// <summary>
30+
/// Gets/sets the reference of the task that has been cancelled
31+
/// </summary>
32+
[DataMember(Name = "task", Order = 2), JsonPropertyName("task"), JsonPropertyOrder(2), YamlMember(Alias = "task", Order = 2)]
33+
public required Uri Task { get; set; }
34+
35+
/// <summary>
36+
/// Gets/sets the date and time at which the workflow instance has been cancelled
37+
/// </summary>
38+
[DataMember(Name = "cancelledAt", Order = 2), JsonPropertyName("cancelledAt"), JsonPropertyOrder(2), YamlMember(Alias = "cancelledAt", Order = 2)]
39+
public DateTimeOffset CancelledAt { get; set; } = DateTimeOffset.Now;
40+
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace Synapse.Events.Tasks;
15+
16+
/// <summary>
17+
/// Represents the data carried by the cloud event that notifies that a task ran to completion
18+
/// </summary>
19+
[CloudEvent(SynapseDefaults.CloudEvents.Task.Completed.v1)]
20+
public record TaskCompletedEventV1
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the qualified name of the workflow instance the task that has completed belongs to
25+
/// </summary>
26+
[DataMember(Name = "workflow", Order = 1), JsonPropertyName("workflow"), JsonPropertyOrder(1), YamlMember(Alias = "workflow", Order = 1)]
27+
public required string Workflow { get; set; }
28+
29+
/// <summary>
30+
/// Gets/sets the reference of the task that has completed
31+
/// </summary>
32+
[DataMember(Name = "task", Order = 2), JsonPropertyName("task"), JsonPropertyOrder(2), YamlMember(Alias = "task", Order = 2)]
33+
public required Uri Task { get; set; }
34+
35+
/// <summary>
36+
/// Gets/sets the date and time at which the task ran to completion
37+
/// </summary>
38+
[DataMember(Name = "completedAt", Order = 3), JsonPropertyName("completedAt"), JsonPropertyOrder(3), YamlMember(Alias = "completedAt", Order = 3)]
39+
public DateTimeOffset CompletedAt { get; set; } = DateTimeOffset.Now;
40+
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace Synapse.Events.Tasks;
15+
16+
/// <summary>
17+
/// Represents the data carried by the cloud event that notifies that a task has been created
18+
/// </summary>
19+
[CloudEvent(SynapseDefaults.CloudEvents.Task.Created.v1)]
20+
public record TaskCreatedEventV1
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the qualified name of the workflow instance the task that has been created belongs to
25+
/// </summary>
26+
[DataMember(Name = "workflow", Order = 1), JsonPropertyName("workflow"), JsonPropertyOrder(1), YamlMember(Alias = "workflow", Order = 1)]
27+
public required string Workflow { get; set; }
28+
29+
/// <summary>
30+
/// Gets/sets the reference of the task that has been created
31+
/// </summary>
32+
[DataMember(Name = "task", Order = 2), JsonPropertyName("task"), JsonPropertyOrder(2), YamlMember(Alias = "task", Order = 2)]
33+
public required Uri Task { get; set; }
34+
35+
/// <summary>
36+
/// Gets/sets the date and time at which the task has been created
37+
/// </summary>
38+
[DataMember(Name = "createdAt", Order = 3), JsonPropertyName("createdAt"), JsonPropertyOrder(3), YamlMember(Alias = "createdAt", Order = 3)]
39+
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.Now;
40+
41+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace Synapse.Events.Tasks;
15+
16+
/// <summary>
17+
/// Represents the data carried by the cloud event that notifies that the execution of a task has ended
18+
/// </summary>
19+
[CloudEvent(SynapseDefaults.CloudEvents.Task.Ended.v1)]
20+
public record TaskEndedEventV1
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the qualified name of the workflow instance the task that has ended belongs to
25+
/// </summary>
26+
[DataMember(Name = "workflow", Order = 1), JsonPropertyName("workflow"), JsonPropertyOrder(1), YamlMember(Alias = "workflow", Order = 1)]
27+
public required string Workflow { get; set; }
28+
29+
/// <summary>
30+
/// Gets/sets the reference of the task that has ended
31+
/// </summary>
32+
[DataMember(Name = "task", Order = 2), JsonPropertyName("task"), JsonPropertyOrder(2), YamlMember(Alias = "task", Order = 2)]
33+
public required Uri Task { get; set; }
34+
35+
/// <summary>
36+
/// Gets/sets the status with which the task ended
37+
/// </summary>
38+
[DataMember(Name = "status", Order = 3), JsonPropertyName("status"), JsonPropertyOrder(3), YamlMember(Alias = "status", Order = 3)]
39+
public required string Status { get; set; }
40+
41+
/// <summary>
42+
/// Gets/sets the date and time at which the task has ended
43+
/// </summary>
44+
[DataMember(Name = "endedAt", Order = 4), JsonPropertyName("endedAt"), JsonPropertyOrder(4), YamlMember(Alias = "endedAt", Order = 4)]
45+
public DateTimeOffset EndedAt { get; set; } = DateTimeOffset.Now;
46+
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace Synapse.Events.Tasks;
15+
16+
/// <summary>
17+
/// Represents the data carried by the cloud event that notifies that a task has faulted
18+
/// </summary>
19+
[CloudEvent(SynapseDefaults.CloudEvents.Task.Faulted.v1)]
20+
public record TaskFaultedEventV1
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the qualified name of the workflow instance the task that has faulted belongs to
25+
/// </summary>
26+
[DataMember(Name = "workflow", Order = 1), JsonPropertyName("workflow"), JsonPropertyOrder(1), YamlMember(Alias = "workflow", Order = 1)]
27+
public required string Workflow { get; set; }
28+
29+
/// <summary>
30+
/// Gets/sets the reference of the task that has faulted
31+
/// </summary>
32+
[DataMember(Name = "task", Order = 2), JsonPropertyName("task"), JsonPropertyOrder(2), YamlMember(Alias = "task", Order = 2)]
33+
public required Uri Task { get; set; }
34+
35+
/// <summary>
36+
/// Gets/sets the error that has cause the task to fault
37+
/// </summary>
38+
[DataMember(Name = "error", Order = 3), JsonPropertyName("error"), JsonPropertyOrder(3), YamlMember(Alias = "error", Order = 3)]
39+
public required Error Error { get; set; }
40+
41+
/// <summary>
42+
/// Gets/sets the date and time at which the task has faulted
43+
/// </summary>
44+
[DataMember(Name = "faultedAt", Order = 4), JsonPropertyName("faultedAt"), JsonPropertyOrder(4), YamlMember(Alias = "faultedAt", Order = 4)]
45+
public DateTimeOffset FaultedAt { get; set; } = DateTimeOffset.Now;
46+
47+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace Synapse.Events.Tasks;
15+
16+
/// <summary>
17+
/// Represents the data carried by the cloud event that notifies that a task has been resumed
18+
/// </summary>
19+
[CloudEvent(SynapseDefaults.CloudEvents.Task.Resumed.v1)]
20+
public record TaskResumedEventV1
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the qualified name of the workflow instance the task that has been resumed
25+
/// </summary>
26+
[DataMember(Name = "workflow", Order = 1), JsonPropertyName("workflow"), JsonPropertyOrder(1), YamlMember(Alias = "workflow", Order = 1)]
27+
public required string Workflow { get; set; }
28+
29+
/// <summary>
30+
/// Gets/sets the reference of the task that has been resumed
31+
/// </summary>
32+
[DataMember(Name = "task", Order = 2), JsonPropertyName("task"), JsonPropertyOrder(2), YamlMember(Alias = "task", Order = 2)]
33+
public required Uri Task { get; set; }
34+
35+
/// <summary>
36+
/// Gets/sets the date and time at which the task has been resumed
37+
/// </summary>
38+
[DataMember(Name = "resumedAt", Order = 2), JsonPropertyName("resumedAt"), JsonPropertyOrder(2), YamlMember(Alias = "resumedAt", Order = 2)]
39+
public DateTimeOffset ResumedAt { get; set; } = DateTimeOffset.Now;
40+
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace Synapse.Events.Tasks;
15+
16+
/// <summary>
17+
/// Represents the data carried by the cloud event that notifies that a task has been skipped
18+
/// </summary>
19+
[CloudEvent(SynapseDefaults.CloudEvents.Task.Skipped.v1)]
20+
public record TaskSkippedEventV1
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the qualified name of the workflow instance the task that has been skipped belongs to
25+
/// </summary>
26+
[DataMember(Name = "workflow", Order = 1), JsonPropertyName("workflow"), JsonPropertyOrder(1), YamlMember(Alias = "workflow", Order = 1)]
27+
public required string Workflow { get; set; }
28+
29+
/// <summary>
30+
/// Gets/sets the reference of the task that has been skipped
31+
/// </summary>
32+
[DataMember(Name = "task", Order = 2), JsonPropertyName("task"), JsonPropertyOrder(2), YamlMember(Alias = "task", Order = 2)]
33+
public required Uri Task { get; set; }
34+
35+
/// <summary>
36+
/// Gets/sets the date and time at which the task has been skipped
37+
/// </summary>
38+
[DataMember(Name = "skippedAt", Order = 3), JsonPropertyName("skippedAt"), JsonPropertyOrder(3), YamlMember(Alias = "skippedAt", Order = 3)]
39+
public DateTimeOffset SkippedAt { get; set; } = DateTimeOffset.Now;
40+
41+
}

0 commit comments

Comments
 (0)