feature: Prometheus Metrics, Supervisor Dashboard, and Promotion Retry Job

This commit is contained in:
voltsrage
2026-06-27 13:29:04 +08:00
parent e22d33b654
commit 04bdb7e85c
31 changed files with 4482 additions and 259 deletions
+1
View File
@@ -22,6 +22,7 @@ public class AppDbContext : DbContext
public DbSet<ClinicalAlert> ClinicalAlerts => Set<ClinicalAlert>();
public DbSet<LiveEncounter> LiveEncounters => Set<LiveEncounter>();
public DbSet<LiveObservation> LiveObservations => Set<LiveObservation>();
public DbSet<PromotionAttempt> PromotionAttempts => Set<PromotionAttempt>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
public class PromotionAttemptConfiguration : IEntityTypeConfiguration<PromotionAttempt>
{
public void Configure(EntityTypeBuilder<PromotionAttempt> builder)
{
builder.ToTable("promotion_attempts");
builder.HasKey(a => a.Id);
builder.Property(a => a.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
builder.Property(a => a.BatchId).HasColumnName("batch_id").IsRequired();
builder.Property(a => a.AttemptNumber).HasColumnName("attempt_number").IsRequired();
builder.Property(a => a.Succeeded).HasColumnName("succeeded").HasDefaultValue(false);
builder.Property(a => a.ErrorMessage).HasColumnName("error_message").HasMaxLength(2000);
builder.Property(a => a.AttemptedAt).HasColumnName("attempted_at").HasDefaultValueSql("NOW()");
builder.Property(a => a.NextRetryAt).HasColumnName("next_retry_at");
builder.HasOne(a => a.Batch)
.WithMany()
.HasForeignKey(a => a.BatchId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasIndex(a => new { a.BatchId, a.AttemptNumber })
.IsUnique()
.HasDatabaseName("ix_promotion_attempts_batch_attempt");
builder.HasIndex(a => a.NextRetryAt)
.HasFilter("succeeded = false AND next_retry_at IS NOT NULL")
.HasDatabaseName("ix_promotion_attempts_pending_retry");
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,57 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace VigilCareRecordsAPI.Data.Migrations
{
/// <inheritdoc />
public partial class AddPromotionAttempts : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "promotion_attempts",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
batch_id = table.Column<Guid>(type: "uuid", nullable: false),
attempt_number = table.Column<int>(type: "integer", nullable: false),
succeeded = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
error_message = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
attempted_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
next_retry_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_promotion_attempts", x => x.id);
table.ForeignKey(
name: "FK_promotion_attempts_digitization_batches_batch_id",
column: x => x.batch_id,
principalTable: "digitization_batches",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "ix_promotion_attempts_batch_attempt",
table: "promotion_attempts",
columns: new[] { "batch_id", "attempt_number" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_promotion_attempts_pending_retry",
table: "promotion_attempts",
column: "next_retry_at",
filter: "succeeded = false AND next_retry_at IS NOT NULL");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "promotion_attempts");
}
}
}
@@ -1055,6 +1055,56 @@ namespace VigilCareRecordsAPI.Data.Migrations
});
});
modelBuilder.Entity("PromotionAttempt", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<int>("AttemptNumber")
.HasColumnType("integer")
.HasColumnName("attempt_number");
b.Property<DateTimeOffset>("AttemptedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("attempted_at")
.HasDefaultValueSql("NOW()");
b.Property<Guid>("BatchId")
.HasColumnType("uuid")
.HasColumnName("batch_id");
b.Property<string>("ErrorMessage")
.HasMaxLength(2000)
.HasColumnType("character varying(2000)")
.HasColumnName("error_message");
b.Property<DateTimeOffset?>("NextRetryAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("next_retry_at");
b.Property<bool>("Succeeded")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasColumnName("succeeded");
b.HasKey("Id");
b.HasIndex("NextRetryAt")
.HasDatabaseName("ix_promotion_attempts_pending_retry")
.HasFilter("succeeded = false AND next_retry_at IS NOT NULL");
b.HasIndex("BatchId", "AttemptNumber")
.IsUnique()
.HasDatabaseName("ix_promotion_attempts_batch_attempt");
b.ToTable("promotion_attempts", (string)null);
});
modelBuilder.Entity("RefreshToken", b =>
{
b.Property<Guid>("Id")
@@ -1345,6 +1395,17 @@ namespace VigilCareRecordsAPI.Data.Migrations
b.Navigation("Patient");
});
modelBuilder.Entity("PromotionAttempt", b =>
{
b.HasOne("DigitizationBatch", "Batch")
.WithMany()
.HasForeignKey("BatchId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Batch");
});
modelBuilder.Entity("RefreshToken", b =>
{
b.HasOne("RefreshToken", "ReplacedByToken")