Adds the scheduled jobs data access layer

This commit is contained in:
BinaryAlley committed 2026-09-03 12:49:07 -07:00
1 parent ea7e003bff
commit bb16cd0bb6
9 files changed
+2382 -6

No files matched your search

@@ -0,0 +1,85 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="ScheduledJobEntity"/> entity.
/// </summary>
public class ScheduledJobConfiguration : IEntityTypeConfiguration<ScheduledJobEntity>
{
/// <summary>
/// Configures the <see cref="ScheduledJobEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<ScheduledJobEntity> builder)
{
builder.ToTable("ScheduledJobs");
builder.HasKey(scheduledJob => scheduledJob.Id);
builder.Property(scheduledJob => scheduledJob.Id)
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
.HasColumnOrder(0);
builder.Property(scheduledJob => scheduledJob.Name)
.IsRequired()
.HasColumnOrder(1);
builder.Property(scheduledJob => scheduledJob.TaskType)
.IsRequired()
.HasConversion<string>()
.HasColumnOrder(2);
builder.Property(scheduledJob => scheduledJob.ScheduleType)
.IsRequired()
.HasConversion<string>()
.HasColumnOrder(3);
builder.Property(scheduledJob => scheduledJob.IntervalMinutes)
.HasColumnOrder(4);
builder.Property(scheduledJob => scheduledJob.Hour)
.HasColumnOrder(5);
builder.Property(scheduledJob => scheduledJob.Minute)
.HasColumnOrder(6);
builder.Property(scheduledJob => scheduledJob.Status)
.IsRequired()
.HasConversion<string>()
.HasColumnOrder(7);
builder.Property(scheduledJob => scheduledJob.OwnerUserId)
.IsRequired()
.HasColumnOrder(8);
builder.Property(scheduledJob => scheduledJob.LastStartedOnUtc)
.HasColumnOrder(9);
builder.Property(scheduledJob => scheduledJob.LastCompletedOnUtc)
.HasColumnOrder(10);
// Audit.
builder.Property(scheduledJob => scheduledJob.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(11);
builder.Property(scheduledJob => scheduledJob.CreatedBy)
.IsRequired()
.HasColumnOrder(12);
builder.Property(scheduledJob => scheduledJob.UpdatedOnUtc)
.HasDefaultValue(null)
.HasColumnOrder(13);
builder.Property(scheduledJob => scheduledJob.UpdatedBy)
.HasDefaultValue(null)
.HasColumnOrder(14);
// Enables fast lookup of the scheduled jobs whose execution cycle is active, at scheduler startup.
builder.HasIndex(scheduledJob => scheduledJob.Status);
}
}
@@ -0,0 +1,68 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="ScheduledJobExecutionEntity"/> entity.
/// </summary>
public class ScheduledJobExecutionConfiguration : IEntityTypeConfiguration<ScheduledJobExecutionEntity>
{
/// <summary>
/// Configures the <see cref="ScheduledJobExecutionEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<ScheduledJobExecutionEntity> builder)
{
builder.ToTable("ScheduledJobExecutions");
builder.HasKey(execution => execution.Id);
builder.Property(execution => execution.Id)
.ValueGeneratedNever()
.HasColumnOrder(0);
builder.Property(execution => execution.ScheduledJobId)
.IsRequired()
.HasColumnOrder(1);
builder.Property(execution => execution.TaskType)
.IsRequired()
.HasConversion<string>()
.HasColumnOrder(2);
builder.Property(execution => execution.IsCycleRun)
.IsRequired()
.HasColumnOrder(3);
builder.Property(execution => execution.StartedOnUtc)
.IsRequired()
.HasColumnOrder(4);
builder.Property(execution => execution.CompletedOnUtc)
.HasColumnOrder(5);
// Audit.
builder.Property(execution => execution.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(6);
builder.Property(execution => execution.CreatedBy)
.IsRequired()
.HasColumnOrder(7);
builder.Property(execution => execution.UpdatedOnUtc)
.HasDefaultValue(null)
.HasColumnOrder(8);
builder.Property(execution => execution.UpdatedBy)
.HasDefaultValue(null)
.HasColumnOrder(9);
// Enables fast queries of the execution history of scheduled jobs by their time range, and the cleanup of the executions of a removed scheduled job.
builder.HasIndex(execution => new { execution.StartedOnUtc, execution.ScheduledJobId });
builder.HasIndex(execution => execution.ScheduledJobId);
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,85 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Lumina.DataAccess.Common.Migrations
{
/// <inheritdoc />
public partial class AddsScheduledJobsTables : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ScheduledJobExecutions",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
ScheduledJobId = table.Column<Guid>(type: "TEXT", nullable: false),
TaskType = table.Column<string>(type: "TEXT", nullable: false),
IsCycleRun = table.Column<bool>(type: "INTEGER", nullable: false),
StartedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
CompletedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ScheduledJobExecutions", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ScheduledJobs",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
TaskType = table.Column<string>(type: "TEXT", nullable: false),
ScheduleType = table.Column<string>(type: "TEXT", nullable: false),
IntervalMinutes = table.Column<int>(type: "INTEGER", nullable: true),
Hour = table.Column<int>(type: "INTEGER", nullable: true),
Minute = table.Column<int>(type: "INTEGER", nullable: true),
Status = table.Column<string>(type: "TEXT", nullable: false),
OwnerUserId = table.Column<Guid>(type: "TEXT", nullable: false),
LastStartedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
LastCompletedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ScheduledJobs", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_ScheduledJobExecutions_ScheduledJobId",
table: "ScheduledJobExecutions",
column: "ScheduledJobId");
migrationBuilder.CreateIndex(
name: "IX_ScheduledJobExecutions_StartedOnUtc_ScheduledJobId",
table: "ScheduledJobExecutions",
columns: new[] { "StartedOnUtc", "ScheduledJobId" });
migrationBuilder.CreateIndex(
name: "IX_ScheduledJobs_Status",
table: "ScheduledJobs",
column: "Status");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ScheduledJobExecutions");
migrationBuilder.DropTable(
name: "ScheduledJobs");
}
}
}
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />.
using System;
using Lumina.DataAccess.Core.UoW;
using Microsoft.EntityFrameworkCore;
@@ -1082,6 +1082,131 @@ namespace Lumina.DataAccess.Common.Migrations
b.ToTable("Plugins", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobEntity", b =>
{
b.Property<Guid>("Id")
.HasColumnType("TEXT")
.HasColumnOrder(0);
b.Property<Guid>("CreatedBy")
.HasColumnType("TEXT")
.HasColumnOrder(12);
b.Property<DateTime>("CreatedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(11);
b.Property<int?>("Hour")
.HasColumnType("INTEGER")
.HasColumnOrder(5);
b.Property<int?>("IntervalMinutes")
.HasColumnType("INTEGER")
.HasColumnOrder(4);
b.Property<DateTime?>("LastCompletedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(10);
b.Property<DateTime?>("LastStartedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(9);
b.Property<int?>("Minute")
.HasColumnType("INTEGER")
.HasColumnOrder(6);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnOrder(1);
b.Property<Guid>("OwnerUserId")
.HasColumnType("TEXT")
.HasColumnOrder(8);
b.Property<string>("ScheduleType")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnOrder(3);
b.Property<string>("Status")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnOrder(7);
b.Property<string>("TaskType")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnOrder(2);
b.Property<Guid?>("UpdatedBy")
.HasColumnType("TEXT")
.HasColumnOrder(14);
b.Property<DateTime?>("UpdatedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(13);
b.HasKey("Id");
b.HasIndex("Status");
b.ToTable("ScheduledJobs", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobExecutionEntity", b =>
{
b.Property<Guid>("Id")
.HasColumnType("TEXT")
.HasColumnOrder(0);
b.Property<DateTime?>("CompletedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(5);
b.Property<Guid>("CreatedBy")
.HasColumnType("TEXT")
.HasColumnOrder(7);
b.Property<DateTime>("CreatedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(6);
b.Property<bool>("IsCycleRun")
.HasColumnType("INTEGER")
.HasColumnOrder(3);
b.Property<Guid>("ScheduledJobId")
.HasColumnType("TEXT")
.HasColumnOrder(1);
b.Property<DateTime>("StartedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(4);
b.Property<string>("TaskType")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnOrder(2);
b.Property<Guid?>("UpdatedBy")
.HasColumnType("TEXT")
.HasColumnOrder(9);
b.Property<DateTime?>("UpdatedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(8);
b.HasKey("Id");
b.HasIndex("ScheduledJobId");
b.HasIndex("StartedOnUtc", "ScheduledJobId");
b.ToTable("ScheduledJobExecutions", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Themes.ThemeEntity", b =>
{
b.Property<Guid>("Id")
@@ -1257,14 +1382,14 @@ namespace Lumina.DataAccess.Common.Migrations
.HasColumnType("INTEGER")
.HasColumnOrder(4);
b.Property<bool>("ShouldRenderPdfAsImages")
.HasColumnType("INTEGER")
.HasColumnOrder(11);
b.Property<bool>("ShouldPreserveBookStyles")
.HasColumnType("INTEGER")
.HasColumnOrder(12);
b.Property<bool>("ShouldRenderPdfAsImages")
.HasColumnType("INTEGER")
.HasColumnOrder(11);
b.Property<Guid?>("UpdatedBy")
.HasColumnType("TEXT")
.HasColumnOrder(8);