Skip to content

Commit

Permalink
fix(Builders): Fix the IContainerProcessDefinitionBuilder and default…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
cdavernas committed Jan 14, 2025
1 parent e4e1632 commit afc5c84
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class ContainerProcessDefinitionBuilder
/// </summary>
protected virtual string? Image { get; set; }

/// <summary>
/// Gets/sets the name of the container to run
/// </summary>
protected virtual string? Name { get; set; }

/// <summary>
/// Gets/sets the command, if any, to execute on the container
/// </summary>
Expand Down Expand Up @@ -56,6 +61,14 @@ public virtual IContainerProcessDefinitionBuilder WithImage(string image)
return this;
}

/// <inheritdoc/>
public virtual IContainerProcessDefinitionBuilder WithName(string name)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name);
this.Name = name;
return this;
}

/// <inheritdoc/>
public virtual IContainerProcessDefinitionBuilder WithCommand(string command)
{
Expand Down Expand Up @@ -122,6 +135,7 @@ public override ContainerProcessDefinition Build()
return new()
{
Image = this.Image,
Name = this.Name,
Command = this.Command,
Ports = this.Ports,
Volumes = this.Volumes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public interface IContainerProcessDefinitionBuilder
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
IContainerProcessDefinitionBuilder WithImage(string image);

/// <summary>
/// Configures the container to use the specified name
/// </summary>
/// <param name="name">The container's name</param>
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
IContainerProcessDefinitionBuilder WithName(string name);

/// <summary>
/// Configures the command, if any, to execute on the container
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public interface IListenerTargetDefinitionBuilder
/// <returns>A new <see cref="IEventFilterDefinitionBuilder"/></returns>
IEventFilterDefinitionBuilder One();

/// <summary>
/// Configures the task to listen to any events until the specified condition expression matches
/// </summary>
/// <param name="expression">A runtime expression that represents the condition that must match for the task to stop consuming events</param>
void Until(string expression);

/// <summary>
/// Configures the task to listen to any events until the specified events are consumed
/// </summary>
/// <param name="setup">An <see cref="Action{T}"/> used to configure the events to consume for the task to stop consuming events</param>
void Until(Action<IListenerTargetDefinitionBuilder> setup);

/// <summary>
/// Builds the configured <see cref="EventConsumptionStrategyDefinition"/>
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public class ListenerTargetDefinitionBuilder
/// </summary>
protected IEventFilterDefinitionBuilder? SingleEvent { get; set; }

/// <summary>
/// Gets the runtime expression that represents the condition that must match for the task to stop consuming events
/// </summary>
protected string? UntilExpression { get; private set; }

/// <summary>
/// Gets the strategy used to configure the events to consume for the task to stop consuming events
/// </summary>
protected EventConsumptionStrategyDefinition? UntilEvents { get; private set; }

/// <inheritdoc/>
public virtual IEventFilterDefinitionCollectionBuilder All()
{
Expand All @@ -56,6 +66,24 @@ public virtual IEventFilterDefinitionBuilder One()
return this.SingleEvent;
}

/// <inheritdoc/>
public virtual void Until(string expression)
{
ArgumentException.ThrowIfNullOrWhiteSpace(expression);
if (this.AnyEvents == null) throw new Exception("The until clause can only be specified when the strategy is used to consume any events");
this.UntilExpression = expression;
}

/// <inheritdoc/>
public virtual void Until(Action<IListenerTargetDefinitionBuilder> setup)
{
ArgumentNullException.ThrowIfNull(setup);
if (this.AnyEvents == null) throw new Exception("The until clause can only be specified when the strategy is used to consume any events");
var builder = new ListenerTargetDefinitionBuilder();
setup(builder);
this.UntilEvents = builder.Build();
}

/// <inheritdoc/>
public virtual EventConsumptionStrategyDefinition Build()
{
Expand All @@ -64,7 +92,9 @@ public virtual EventConsumptionStrategyDefinition Build()
{
All = this.AllEvents?.Build(),
Any = this.AnyEvents?.Build(),
One = this.SingleEvent?.Build()
One = this.SingleEvent?.Build(),
UntilExpression = this.UntilExpression,
Until = this.UntilEvents
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

namespace ServerlessWorkflow.Sdk.Models.Tasks;
namespace ServerlessWorkflow.Sdk.Models;

/// <summary>
/// Represents an object used to configure branches to perform concurrently
Expand Down
2 changes: 1 addition & 1 deletion src/ServerlessWorkflow.Sdk/Models/ForLoopDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ServerlessWorkflow.Sdk.Models;
public record ForLoopDefinition
{

/// <summary>
/// <summary>
/// Gets/sets the name of the variable that represents each element in the collection during iteration
/// </summary>
[Required]
Expand Down
2 changes: 1 addition & 1 deletion src/ServerlessWorkflow.Sdk/Models/RaiseErrorDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public virtual string? ErrorReference
}

/// <summary>
/// Gets/sets the endpoint at which to get the defined resource
/// Gets/sets the error to raise
/// </summary>
[Required]
[DataMember(Name = "error", Order = 1), JsonInclude, JsonPropertyName("error"), JsonPropertyOrder(1), YamlMember(Alias = "error", Order = 1)]
Expand Down

0 comments on commit afc5c84

Please sign in to comment.