Skip to content

Commit

Permalink
feat(ES.FX.OneOf): add Failure types
Browse files Browse the repository at this point in the history
- Introduced a new record struct, `Failure`.
- Added a generic version of the `Failure` struct, `Failure<T>`, to hold any type of value.
  • Loading branch information
winromulus committed Oct 5, 2024
1 parent 1d85dc6 commit 6e46353
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.5" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.6" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.8" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#pragma warning disable CS9113 // Parameter is unread.

using ES.FX.StackExchange.Redis;
using ES.FX.TransactionalOutbox.EntityFrameworkCore;
using ES.FX.TransactionalOutbox.EntityFrameworkCore.Messages;
using Microsoft.EntityFrameworkCore;
using Playground.Microservice.Api.Host.Testing;
using Playground.Shared.Data.Simple.EntityFrameworkCore;
using Playground.Shared.Data.Simple.EntityFrameworkCore.Entities;
using StackExchange.Redis;
using StackExchange.Redis.KeyspaceIsolation;

namespace Playground.Microservice.Api.Host.HostedServices;

Expand All @@ -32,7 +29,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
DelayBetweenAttempts = 5,
DelayBetweenAttemptsIsExponential = true
});
dbContext.SimpleUsers.Add(new SimpleUser { Id = Guid.NewGuid(), Username = Guid.NewGuid().ToString()});
dbContext.SimpleUsers.Add(new SimpleUser { Id = Guid.NewGuid(), Username = Guid.NewGuid().ToString() });
}

await dbContext.SaveChangesAsync(stoppingToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,123 +1,109 @@
using System;
#nullable disable

using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable
namespace Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer.Migrations;

namespace Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer.Migrations
/// <inheritdoc />
public partial class V1 : Migration
{
/// <inheritdoc />
public partial class V1 : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "__Outboxes",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
AddedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
Lock = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
DeliveryDelayedUntil = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
RowVersion = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK___Outboxes", x => x.Id);
});
migrationBuilder.CreateTable(
"__Outboxes",
table => new
{
Id = table.Column<Guid>("uniqueidentifier", nullable: false),
AddedAt = table.Column<DateTimeOffset>("datetimeoffset", nullable: false),
Lock = table.Column<Guid>("uniqueidentifier", nullable: true),
DeliveryDelayedUntil = table.Column<DateTimeOffset>("datetimeoffset", nullable: true),
RowVersion = table.Column<byte[]>("rowversion", rowVersion: true, nullable: true)
},
constraints: table => { table.PrimaryKey("PK___Outboxes", x => x.Id); });

migrationBuilder.CreateTable(
name: "__OutboxMessageFaults",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
OutboxId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
AddedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
Headers = table.Column<string>(type: "nvarchar(max)", nullable: false),
PayloadType = table.Column<string>(type: "nvarchar(max)", nullable: false),
Payload = table.Column<string>(type: "nvarchar(max)", nullable: false),
DeliveryAttempts = table.Column<int>(type: "int", nullable: false),
DeliveryFirstAttemptedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
DeliveryLastAttemptedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
DeliveryLastAttemptError = table.Column<string>(type: "nvarchar(4000)", maxLength: 4000, nullable: true),
DeliveryNotBefore = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
DeliveryNotAfter = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
FaultedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK___OutboxMessageFaults", x => x.Id);
});
migrationBuilder.CreateTable(
"__OutboxMessageFaults",
table => new
{
Id = table.Column<long>("bigint", nullable: false),
OutboxId = table.Column<Guid>("uniqueidentifier", nullable: false),
AddedAt = table.Column<DateTimeOffset>("datetimeoffset", nullable: false),
Headers = table.Column<string>("nvarchar(max)", nullable: false),
PayloadType = table.Column<string>("nvarchar(max)", nullable: false),
Payload = table.Column<string>("nvarchar(max)", nullable: false),
DeliveryAttempts = table.Column<int>("int", nullable: false),
DeliveryFirstAttemptedAt = table.Column<DateTimeOffset>("datetimeoffset", nullable: true),
DeliveryLastAttemptedAt = table.Column<DateTimeOffset>("datetimeoffset", nullable: true),
DeliveryLastAttemptError = table.Column<string>("nvarchar(4000)", maxLength: 4000, nullable: true),
DeliveryNotBefore = table.Column<DateTimeOffset>("datetimeoffset", nullable: true),
DeliveryNotAfter = table.Column<DateTimeOffset>("datetimeoffset", nullable: true),
FaultedAt = table.Column<DateTimeOffset>("datetimeoffset", nullable: false)
},
constraints: table => { table.PrimaryKey("PK___OutboxMessageFaults", x => x.Id); });

migrationBuilder.CreateTable(
name: "__OutboxMessages",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OutboxId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
AddedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
Headers = table.Column<string>(type: "nvarchar(max)", nullable: false),
PayloadType = table.Column<string>(type: "nvarchar(max)", nullable: false),
Payload = table.Column<string>(type: "nvarchar(max)", nullable: false),
DeliveryAttempts = table.Column<int>(type: "int", nullable: false),
DeliveryMaxAttempts = table.Column<int>(type: "int", nullable: true),
DeliveryFirstAttemptedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
DeliveryLastAttemptedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
DeliveryLastAttemptError = table.Column<string>(type: "nvarchar(4000)", maxLength: 4000, nullable: true),
DeliveryNotBefore = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
DeliveryNotAfter = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
DeliveryAttemptDelay = table.Column<int>(type: "int", nullable: false),
DeliveryAttemptDelayIsExponential = table.Column<bool>(type: "bit", nullable: false),
RowVersion = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK___OutboxMessages", x => x.Id);
});
migrationBuilder.CreateTable(
"__OutboxMessages",
table => new
{
Id = table.Column<long>("bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OutboxId = table.Column<Guid>("uniqueidentifier", nullable: false),
AddedAt = table.Column<DateTimeOffset>("datetimeoffset", nullable: false),
Headers = table.Column<string>("nvarchar(max)", nullable: false),
PayloadType = table.Column<string>("nvarchar(max)", nullable: false),
Payload = table.Column<string>("nvarchar(max)", nullable: false),
DeliveryAttempts = table.Column<int>("int", nullable: false),
DeliveryMaxAttempts = table.Column<int>("int", nullable: true),
DeliveryFirstAttemptedAt = table.Column<DateTimeOffset>("datetimeoffset", nullable: true),
DeliveryLastAttemptedAt = table.Column<DateTimeOffset>("datetimeoffset", nullable: true),
DeliveryLastAttemptError = table.Column<string>("nvarchar(4000)", maxLength: 4000, nullable: true),
DeliveryNotBefore = table.Column<DateTimeOffset>("datetimeoffset", nullable: true),
DeliveryNotAfter = table.Column<DateTimeOffset>("datetimeoffset", nullable: true),
DeliveryAttemptDelay = table.Column<int>("int", nullable: false),
DeliveryAttemptDelayIsExponential = table.Column<bool>("bit", nullable: false),
RowVersion = table.Column<byte[]>("rowversion", rowVersion: true, nullable: true)
},
constraints: table => { table.PrimaryKey("PK___OutboxMessages", x => x.Id); });

migrationBuilder.CreateTable(
name: "SimpleUsers",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Username = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SimpleUsers", x => x.Id);
});
migrationBuilder.CreateTable(
"SimpleUsers",
table => new
{
Id = table.Column<Guid>("uniqueidentifier", nullable: false),
Username = table.Column<string>("nvarchar(128)", maxLength: 128, nullable: false)
},
constraints: table => { table.PrimaryKey("PK_SimpleUsers", x => x.Id); });

migrationBuilder.CreateIndex(
name: "IX___Outboxes_AddedAt",
table: "__Outboxes",
column: "AddedAt");
migrationBuilder.CreateIndex(
"IX___Outboxes_AddedAt",
"__Outboxes",
"AddedAt");

migrationBuilder.CreateIndex(
name: "IX___Outboxes_DeliveryDelayedUntil",
table: "__Outboxes",
column: "DeliveryDelayedUntil");
migrationBuilder.CreateIndex(
"IX___Outboxes_DeliveryDelayedUntil",
"__Outboxes",
"DeliveryDelayedUntil");

migrationBuilder.CreateIndex(
name: "IX___Outboxes_Lock",
table: "__Outboxes",
column: "Lock");
}
migrationBuilder.CreateIndex(
"IX___Outboxes_Lock",
"__Outboxes",
"Lock");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "__Outboxes");
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
"__Outboxes");

migrationBuilder.DropTable(
name: "__OutboxMessageFaults");
migrationBuilder.DropTable(
"__OutboxMessageFaults");

migrationBuilder.DropTable(
name: "__OutboxMessages");
migrationBuilder.DropTable(
"__OutboxMessages");

migrationBuilder.DropTable(
name: "SimpleUsers");
}
migrationBuilder.DropTable(
"SimpleUsers");
}
}
}
2 changes: 1 addition & 1 deletion src/ES.FX.Contracts/Messaging/MessageTypeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public class MessageTypeAttribute(string messageType) : Attribute
return attribute?.MessageType;
}

public static string? MessageTypeFor<T>() =>
public static string? MessageTypeFor<T>() =>
MessageTypeFor(typeof(T));
}
5 changes: 5 additions & 0 deletions src/ES.FX.OneOf/Types/Failure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace ES.FX.OneOf.Types;

public record struct Failure;

public record struct Failure<T>(T Value);
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ await dbContext.Database.CreateExecutionStrategy().ExecuteAsync(async () =>
}
finally
{

deliverOutboxActivity?.Stop();
deliverOutboxActivity?.Dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ await ProgramEntry.CreateBuilder([]).UseSerilog(LogEventLevel.Verbose,
Assert.NotEmpty(InMemorySink.Instance.LogEvents);
return Task.FromResult(1);
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void KeysDelete_Input_Output_check(string pattern, int batchSize)
batchSize);

database.Verify(database => database.ScriptEvaluate(It.IsAny<string>(),
It.Is<RedisKey[]>(x=>x.Contains(pattern)),
It.Is<RedisKey[]>(x => x.Contains(pattern)),
It.Is<RedisValue[]>(x => x.Contains(batchSize)),
It.IsAny<CommandFlags>()), Times.Once);
}
Expand Down

0 comments on commit 6e46353

Please sign in to comment.