Skip to content

Commit afc5c84

Browse files
committed
fix(Builders): Fix the IContainerProcessDefinitionBuilder and default implementation to allow configuring the container name
fix(Builders): Fix the IListenerTargetDefinitionBuilder and default implementation to allow configuring the `until`clause fix(Core): Minor fixes and improvements Signed-off-by: Charles d'Avernas <[email protected]>
1 parent e4e1632 commit afc5c84

7 files changed

+67
-4
lines changed

Diff for: src/ServerlessWorkflow.Sdk.Builders/ContainerProcessDefinitionBuilder.cs

+14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public class ContainerProcessDefinitionBuilder
2828
/// </summary>
2929
protected virtual string? Image { get; set; }
3030

31+
/// <summary>
32+
/// Gets/sets the name of the container to run
33+
/// </summary>
34+
protected virtual string? Name { get; set; }
35+
3136
/// <summary>
3237
/// Gets/sets the command, if any, to execute on the container
3338
/// </summary>
@@ -56,6 +61,14 @@ public virtual IContainerProcessDefinitionBuilder WithImage(string image)
5661
return this;
5762
}
5863

64+
/// <inheritdoc/>
65+
public virtual IContainerProcessDefinitionBuilder WithName(string name)
66+
{
67+
ArgumentException.ThrowIfNullOrWhiteSpace(name);
68+
this.Name = name;
69+
return this;
70+
}
71+
5972
/// <inheritdoc/>
6073
public virtual IContainerProcessDefinitionBuilder WithCommand(string command)
6174
{
@@ -122,6 +135,7 @@ public override ContainerProcessDefinition Build()
122135
return new()
123136
{
124137
Image = this.Image,
138+
Name = this.Name,
125139
Command = this.Command,
126140
Ports = this.Ports,
127141
Volumes = this.Volumes,

Diff for: src/ServerlessWorkflow.Sdk.Builders/Interfaces/IContainerProcessDefinitionBuilder.cs

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public interface IContainerProcessDefinitionBuilder
2929
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
3030
IContainerProcessDefinitionBuilder WithImage(string image);
3131

32+
/// <summary>
33+
/// Configures the container to use the specified name
34+
/// </summary>
35+
/// <param name="name">The container's name</param>
36+
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
37+
IContainerProcessDefinitionBuilder WithName(string name);
38+
3239
/// <summary>
3340
/// Configures the command, if any, to execute on the container
3441
/// </summary>

Diff for: src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerTargetDefinitionBuilder.cs

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public interface IListenerTargetDefinitionBuilder
3737
/// <returns>A new <see cref="IEventFilterDefinitionBuilder"/></returns>
3838
IEventFilterDefinitionBuilder One();
3939

40+
/// <summary>
41+
/// Configures the task to listen to any events until the specified condition expression matches
42+
/// </summary>
43+
/// <param name="expression">A runtime expression that represents the condition that must match for the task to stop consuming events</param>
44+
void Until(string expression);
45+
46+
/// <summary>
47+
/// Configures the task to listen to any events until the specified events are consumed
48+
/// </summary>
49+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the events to consume for the task to stop consuming events</param>
50+
void Until(Action<IListenerTargetDefinitionBuilder> setup);
51+
4052
/// <summary>
4153
/// Builds the configured <see cref="EventConsumptionStrategyDefinition"/>
4254
/// </summary>

Diff for: src/ServerlessWorkflow.Sdk.Builders/ListenerTargetDefinitionBuilder.cs

+31-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public class ListenerTargetDefinitionBuilder
3535
/// </summary>
3636
protected IEventFilterDefinitionBuilder? SingleEvent { get; set; }
3737

38+
/// <summary>
39+
/// Gets the runtime expression that represents the condition that must match for the task to stop consuming events
40+
/// </summary>
41+
protected string? UntilExpression { get; private set; }
42+
43+
/// <summary>
44+
/// Gets the strategy used to configure the events to consume for the task to stop consuming events
45+
/// </summary>
46+
protected EventConsumptionStrategyDefinition? UntilEvents { get; private set; }
47+
3848
/// <inheritdoc/>
3949
public virtual IEventFilterDefinitionCollectionBuilder All()
4050
{
@@ -56,6 +66,24 @@ public virtual IEventFilterDefinitionBuilder One()
5666
return this.SingleEvent;
5767
}
5868

69+
/// <inheritdoc/>
70+
public virtual void Until(string expression)
71+
{
72+
ArgumentException.ThrowIfNullOrWhiteSpace(expression);
73+
if (this.AnyEvents == null) throw new Exception("The until clause can only be specified when the strategy is used to consume any events");
74+
this.UntilExpression = expression;
75+
}
76+
77+
/// <inheritdoc/>
78+
public virtual void Until(Action<IListenerTargetDefinitionBuilder> setup)
79+
{
80+
ArgumentNullException.ThrowIfNull(setup);
81+
if (this.AnyEvents == null) throw new Exception("The until clause can only be specified when the strategy is used to consume any events");
82+
var builder = new ListenerTargetDefinitionBuilder();
83+
setup(builder);
84+
this.UntilEvents = builder.Build();
85+
}
86+
5987
/// <inheritdoc/>
6088
public virtual EventConsumptionStrategyDefinition Build()
6189
{
@@ -64,7 +92,9 @@ public virtual EventConsumptionStrategyDefinition Build()
6492
{
6593
All = this.AllEvents?.Build(),
6694
Any = this.AnyEvents?.Build(),
67-
One = this.SingleEvent?.Build()
95+
One = this.SingleEvent?.Build(),
96+
UntilExpression = this.UntilExpression,
97+
Until = this.UntilEvents
6898
};
6999
}
70100

Diff for: src/ServerlessWorkflow.Sdk/Models/Tasks/BranchingDefinition.cs renamed to src/ServerlessWorkflow.Sdk/Models/BranchingDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
namespace ServerlessWorkflow.Sdk.Models.Tasks;
14+
namespace ServerlessWorkflow.Sdk.Models;
1515

1616
/// <summary>
1717
/// Represents an object used to configure branches to perform concurrently

Diff for: src/ServerlessWorkflow.Sdk/Models/ForLoopDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ServerlessWorkflow.Sdk.Models;
2020
public record ForLoopDefinition
2121
{
2222

23-
/// <summary>
23+
/// <summary>
2424
/// Gets/sets the name of the variable that represents each element in the collection during iteration
2525
/// </summary>
2626
[Required]

Diff for: src/ServerlessWorkflow.Sdk/Models/RaiseErrorDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public virtual string? ErrorReference
4949
}
5050

5151
/// <summary>
52-
/// Gets/sets the endpoint at which to get the defined resource
52+
/// Gets/sets the error to raise
5353
/// </summary>
5454
[Required]
5555
[DataMember(Name = "error", Order = 1), JsonInclude, JsonPropertyName("error"), JsonPropertyOrder(1), YamlMember(Alias = "error", Order = 1)]

0 commit comments

Comments
 (0)