feat(reliability): Outbox Poller Hangfire job with inbox idempotency
Implement async outbox polling and event publishing to inbox using Hangfire. Completes AGENTS.md v16.0 Outbox/Inbox crash-recovery validation gate. Changes: - DapperOutboxMessageReader: async reader with InsertInboxAsync for idempotent publishing - OutboxPollerJob: recurring Hangfire job (q-research, 3 retries, max 100 batch) * Polls unpublished messages (PIT-safe cutoff: now - 5 min) * Publishes to inbox_message (consumer='outbox-poller') * Marks published_at + increments attempt counter * Dead-letters messages after 3 attempts - Program.cs: Register DapperOutboxMessageReader, schedule outbox-poller every minute UTC - appsettings.json: Kestrel 5002 port binding for nginx upstream - Integration.Tests: 3/3 passing scenarios (normal, PIT cutoff, max-attempts) AGENTS.md v16.0 Checklist: ✅ SOLID (single responsibility, DI) ✅ Complexity (cyclomatic < 10) ✅ Audit (PIT query, published_at tracking, attempt counter) ✅ Necessity (CLAUDE.md: "Hangfire job polls outbox, publishes events") ✅ Normalization (3NF outbox, idempotent inbox PK, job_run audit) ✅ Simplicity (schema-qualified SQL, no SELECT *) ✅ Pattern (Hangfire job, on conflict do nothing) ✅ Guardrails (no magic values, crash-safe) ✅ Traceability (EventIds, LoggerMessage, correlation_id) ✅ Safety (atomic operations, idempotent inbox, no partial success) ✅ Maturity (Contract→Implementation→Test: 3/3 passing) ✅ Right Way (no force/no-verify, proper retry classification) ✅ Debt (zero new tech debt; consumer='outbox-poller' minimal & extensible) Validation gates: 5/8 passed - ✅ .NET 10 build/test - ✅ pnpm typecheck/build - ✅ DbUp fresh/upgrade - ✅ Kestrel 5002 + nginx verified - ✅ Outbox/Inbox crash-recovery Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ using FastEndpoints;
|
||||
using Hangfire;
|
||||
using Hangfire.PostgreSql;
|
||||
using KArtSell.BuildingBlocks.Capabilities;
|
||||
using KArtSell.Host.Jobs;
|
||||
using KArtSell.BuildingBlocks.Data;
|
||||
using KArtSell.BuildingBlocks.Reliability;
|
||||
using KArtSell.BuildingBlocks.Time;
|
||||
@@ -44,6 +45,7 @@ builder.Services.AddSingleton<IDbConnectionFactory, NpgsqlConnectionFactory>();
|
||||
builder.Services.AddSingleton<IOutboxWriter, DapperOutboxWriter>();
|
||||
builder.Services.AddSingleton<IInboxStore, DapperInboxStore>();
|
||||
builder.Services.AddSingleton<IJobRunRepository, DapperJobRunRepository>();
|
||||
builder.Services.AddSingleton<DapperOutboxMessageReader>();
|
||||
builder.Services.AddSingleton<IClock, KArtSell.BuildingBlocks.Time.SystemClock>();
|
||||
|
||||
builder.Services.AddProblemDetails();
|
||||
@@ -126,6 +128,12 @@ app.UseFastEndpoints(config => config.Endpoints.RoutePrefix = "api");
|
||||
|
||||
app.Services.RegisterModelOperationsSchedules(modelOperationsDispatcherEnabled, modelOperationsDispatcherCron);
|
||||
|
||||
RecurringJob.AddOrUpdate<OutboxPollerJob>(
|
||||
"outbox-poller",
|
||||
job => job.ExecuteAsync(CancellationToken.None),
|
||||
"* * * * *",
|
||||
new RecurringJobOptions { TimeZone = TimeZoneInfo.Utc });
|
||||
|
||||
app.MapGet("/health/live", () => Results.Ok(new
|
||||
{
|
||||
status = "ok",
|
||||
|
||||
Reference in New Issue
Block a user