From c94a3b41c9df4496d66fb8a5b432ff552def0ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Mon, 8 Dec 2025 21:54:48 +0100 Subject: [PATCH] Duplicate models fields fix --- DiunaBI.API/Controllers/JobsController.cs | 13 +- DiunaBI.Domain/Entities/QueueJob.cs | 3 +- DiunaBI.Domain/Entities/User.cs | 5 + DiunaBI.Infrastructure/Data/AppDbContext.cs | 3 +- ...moveQueueJobDuplicateUTCFields.Designer.cs | 489 ++++++++++++++++++ ...205202_RemoveQueueJobDuplicateUTCFields.cs | 52 ++ .../Migrations/AppDbContextModelSnapshot.cs | 23 +- .../Services/JobSchedulerService.cs | 14 +- .../Services/JobWorkerService.cs | 12 +- 9 files changed, 580 insertions(+), 34 deletions(-) create mode 100644 DiunaBI.Infrastructure/Migrations/20251208205202_RemoveQueueJobDuplicateUTCFields.Designer.cs create mode 100644 DiunaBI.Infrastructure/Migrations/20251208205202_RemoveQueueJobDuplicateUTCFields.cs diff --git a/DiunaBI.API/Controllers/JobsController.cs b/DiunaBI.API/Controllers/JobsController.cs index ce4ed4d..cab4503 100644 --- a/DiunaBI.API/Controllers/JobsController.cs +++ b/DiunaBI.API/Controllers/JobsController.cs @@ -227,7 +227,8 @@ public class JobsController : Controller job.Status = JobStatus.Pending; job.RetryCount = 0; job.LastError = null; - job.ModifiedAtUtc = DateTime.UtcNow; + job.ModifiedAt = DateTime.UtcNow; + job.ModifiedById = DiunaBI.Domain.Entities.User.AutoImportUserId; await _db.SaveChangesAsync(); @@ -274,7 +275,8 @@ public class JobsController : Controller job.Status = JobStatus.Failed; job.LastError = "Cancelled by user"; - job.ModifiedAtUtc = DateTime.UtcNow; + job.ModifiedAt = DateTime.UtcNow; + job.ModifiedById = DiunaBI.Domain.Entities.User.AutoImportUserId; await _db.SaveChangesAsync(); @@ -405,10 +407,9 @@ public class JobsController : Controller MaxRetries = maxRetries, Status = JobStatus.Pending, CreatedAt = DateTime.UtcNow, - CreatedAtUtc = DateTime.UtcNow, - ModifiedAtUtc = DateTime.UtcNow, - CreatedById = Guid.Empty, - ModifiedById = Guid.Empty + ModifiedAt = DateTime.UtcNow, + CreatedById = DiunaBI.Domain.Entities.User.AutoImportUserId, + ModifiedById = DiunaBI.Domain.Entities.User.AutoImportUserId }; _db.QueueJobs.Add(job); diff --git a/DiunaBI.Domain/Entities/QueueJob.cs b/DiunaBI.Domain/Entities/QueueJob.cs index bb44b7a..5545852 100644 --- a/DiunaBI.Domain/Entities/QueueJob.cs +++ b/DiunaBI.Domain/Entities/QueueJob.cs @@ -12,6 +12,7 @@ public class QueueJob public JobType JobType { get; set; } public int Priority { get; set; } = 0; // 0 = highest priority public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + public DateTime ModifiedAt { get; set; } = DateTime.UtcNow; public int RetryCount { get; set; } = 0; public int MaxRetries { get; set; } = 5; public JobStatus Status { get; set; } = JobStatus.Pending; @@ -19,9 +20,7 @@ public class QueueJob public DateTime? LastAttemptAt { get; set; } public DateTime? CompletedAt { get; set; } public Guid CreatedById { get; set; } - public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; public Guid ModifiedById { get; set; } - public DateTime ModifiedAtUtc { get; set; } = DateTime.UtcNow; } public enum JobType diff --git a/DiunaBI.Domain/Entities/User.cs b/DiunaBI.Domain/Entities/User.cs index 59a60cc..b18d74b 100644 --- a/DiunaBI.Domain/Entities/User.cs +++ b/DiunaBI.Domain/Entities/User.cs @@ -5,6 +5,11 @@ namespace DiunaBI.Domain.Entities; public class User { + /// + /// System user ID for automated operations (imports, scheduled jobs, etc.) + /// + public static readonly Guid AutoImportUserId = Guid.Parse("f392209e-123e-4651-a5a4-0b1d6cf9ff9d"); + #region Properties public Guid Id { get; init; } public string? Email { get; init; } diff --git a/DiunaBI.Infrastructure/Data/AppDbContext.cs b/DiunaBI.Infrastructure/Data/AppDbContext.cs index 4110933..58b5280 100644 --- a/DiunaBI.Infrastructure/Data/AppDbContext.cs +++ b/DiunaBI.Infrastructure/Data/AppDbContext.cs @@ -136,9 +136,8 @@ public class AppDbContext(DbContextOptions options) : DbContext(op modelBuilder.Entity().Property(x => x.LastAttemptAt); modelBuilder.Entity().Property(x => x.CompletedAt); modelBuilder.Entity().Property(x => x.CreatedById).IsRequired(); - modelBuilder.Entity().Property(x => x.CreatedAtUtc).IsRequired(); modelBuilder.Entity().Property(x => x.ModifiedById).IsRequired(); - modelBuilder.Entity().Property(x => x.ModifiedAtUtc).IsRequired(); + modelBuilder.Entity().Property(x => x.ModifiedAt).IsRequired(); // Configure automatic timestamps for entities with CreatedAt/ModifiedAt ConfigureTimestamps(modelBuilder); diff --git a/DiunaBI.Infrastructure/Migrations/20251208205202_RemoveQueueJobDuplicateUTCFields.Designer.cs b/DiunaBI.Infrastructure/Migrations/20251208205202_RemoveQueueJobDuplicateUTCFields.Designer.cs new file mode 100644 index 0000000..218d1ad --- /dev/null +++ b/DiunaBI.Infrastructure/Migrations/20251208205202_RemoveQueueJobDuplicateUTCFields.Designer.cs @@ -0,0 +1,489 @@ +// +using System; +using DiunaBI.Infrastructure.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DiunaBI.Infrastructure.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20251208205202_RemoveQueueJobDuplicateUTCFields")] + partial class RemoveQueueJobDuplicateUTCFields + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DiunaBI.Domain.Entities.DataInbox", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("Data") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("DataInbox"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.Layer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("IsCancelled") + .ValueGeneratedOnAdd() + .HasColumnType("bit") + .HasDefaultValue(false); + + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnType("bit") + .HasDefaultValue(false); + + b.Property("ModifiedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("ModifiedById"); + + b.ToTable("Layers"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.ProcessSource", b => + { + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("SourceId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("LayerId", "SourceId"); + + b.HasIndex("SourceId"); + + b.ToTable("ProcessSources"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.QueueJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CompletedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("JobType") + .HasColumnType("int"); + + b.Property("LastAttemptAt") + .HasColumnType("datetime2"); + + b.Property("LastError") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("LayerName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("MaxRetries") + .HasColumnType("int"); + + b.Property("ModifiedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("PluginName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Priority") + .HasColumnType("int"); + + b.Property("RetryCount") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("QueueJobs"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.Record", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasMaxLength(10000) + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ModifiedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Value1") + .HasColumnType("float"); + + b.Property("Value10") + .HasColumnType("float"); + + b.Property("Value11") + .HasColumnType("float"); + + b.Property("Value12") + .HasColumnType("float"); + + b.Property("Value13") + .HasColumnType("float"); + + b.Property("Value14") + .HasColumnType("float"); + + b.Property("Value15") + .HasColumnType("float"); + + b.Property("Value16") + .HasColumnType("float"); + + b.Property("Value17") + .HasColumnType("float"); + + b.Property("Value18") + .HasColumnType("float"); + + b.Property("Value19") + .HasColumnType("float"); + + b.Property("Value2") + .HasColumnType("float"); + + b.Property("Value20") + .HasColumnType("float"); + + b.Property("Value21") + .HasColumnType("float"); + + b.Property("Value22") + .HasColumnType("float"); + + b.Property("Value23") + .HasColumnType("float"); + + b.Property("Value24") + .HasColumnType("float"); + + b.Property("Value25") + .HasColumnType("float"); + + b.Property("Value26") + .HasColumnType("float"); + + b.Property("Value27") + .HasColumnType("float"); + + b.Property("Value28") + .HasColumnType("float"); + + b.Property("Value29") + .HasColumnType("float"); + + b.Property("Value3") + .HasColumnType("float"); + + b.Property("Value30") + .HasColumnType("float"); + + b.Property("Value31") + .HasColumnType("float"); + + b.Property("Value32") + .HasColumnType("float"); + + b.Property("Value4") + .HasColumnType("float"); + + b.Property("Value5") + .HasColumnType("float"); + + b.Property("Value6") + .HasColumnType("float"); + + b.Property("Value7") + .HasColumnType("float"); + + b.Property("Value8") + .HasColumnType("float"); + + b.Property("Value9") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("LayerId"); + + b.HasIndex("ModifiedById"); + + b.ToTable("Records"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.RecordHistory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("ChangeType") + .HasColumnType("int"); + + b.Property("ChangedAt") + .HasColumnType("datetime2"); + + b.Property("ChangedById") + .HasColumnType("uniqueidentifier"); + + b.Property("ChangedFields") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ChangesSummary") + .HasMaxLength(4000) + .HasColumnType("nvarchar(4000)"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Desc1") + .HasMaxLength(10000) + .HasColumnType("nvarchar(max)"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("RecordId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ChangedById"); + + b.HasIndex("LayerId", "ChangedAt"); + + b.HasIndex("RecordId", "ChangedAt"); + + b.ToTable("RecordHistory"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("Email") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("UserName") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.Layer", b => + { + b.HasOne("DiunaBI.Domain.Entities.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("DiunaBI.Domain.Entities.User", "ModifiedBy") + .WithMany() + .HasForeignKey("ModifiedById") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.ProcessSource", b => + { + b.HasOne("DiunaBI.Domain.Entities.Layer", null) + .WithMany() + .HasForeignKey("LayerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DiunaBI.Domain.Entities.Layer", "Source") + .WithMany() + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Source"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.Record", b => + { + b.HasOne("DiunaBI.Domain.Entities.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("DiunaBI.Domain.Entities.Layer", null) + .WithMany("Records") + .HasForeignKey("LayerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DiunaBI.Domain.Entities.User", "ModifiedBy") + .WithMany() + .HasForeignKey("ModifiedById") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.RecordHistory", b => + { + b.HasOne("DiunaBI.Domain.Entities.User", "ChangedBy") + .WithMany() + .HasForeignKey("ChangedById") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("ChangedBy"); + }); + + modelBuilder.Entity("DiunaBI.Domain.Entities.Layer", b => + { + b.Navigation("Records"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DiunaBI.Infrastructure/Migrations/20251208205202_RemoveQueueJobDuplicateUTCFields.cs b/DiunaBI.Infrastructure/Migrations/20251208205202_RemoveQueueJobDuplicateUTCFields.cs new file mode 100644 index 0000000..7586b3c --- /dev/null +++ b/DiunaBI.Infrastructure/Migrations/20251208205202_RemoveQueueJobDuplicateUTCFields.cs @@ -0,0 +1,52 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Infrastructure.Migrations +{ + /// + public partial class RemoveQueueJobDuplicateUTCFields : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CreatedAtUtc", + table: "QueueJobs"); + + migrationBuilder.DropColumn( + name: "ModifiedAtUtc", + table: "QueueJobs"); + + migrationBuilder.AddColumn( + name: "ModifiedAt", + table: "QueueJobs", + type: "datetime2", + nullable: false, + defaultValueSql: "GETUTCDATE()"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ModifiedAt", + table: "QueueJobs"); + + migrationBuilder.AddColumn( + name: "CreatedAtUtc", + table: "QueueJobs", + type: "datetime2", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + + migrationBuilder.AddColumn( + name: "ModifiedAtUtc", + table: "QueueJobs", + type: "datetime2", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + } + } +} diff --git a/DiunaBI.Infrastructure/Migrations/AppDbContextModelSnapshot.cs b/DiunaBI.Infrastructure/Migrations/AppDbContextModelSnapshot.cs index dd69cee..08fa40a 100644 --- a/DiunaBI.Infrastructure/Migrations/AppDbContextModelSnapshot.cs +++ b/DiunaBI.Infrastructure/Migrations/AppDbContextModelSnapshot.cs @@ -49,7 +49,7 @@ namespace DiunaBI.Infrastructure.Migrations b.HasKey("Id"); - b.ToTable("DataInbox", (string)null); + b.ToTable("DataInbox"); }); modelBuilder.Entity("DiunaBI.Domain.Entities.Layer", b => @@ -104,7 +104,7 @@ namespace DiunaBI.Infrastructure.Migrations b.HasIndex("ModifiedById"); - b.ToTable("Layers", (string)null); + b.ToTable("Layers"); }); modelBuilder.Entity("DiunaBI.Domain.Entities.ProcessSource", b => @@ -119,7 +119,7 @@ namespace DiunaBI.Infrastructure.Migrations b.HasIndex("SourceId"); - b.ToTable("ProcessSources", (string)null); + b.ToTable("ProcessSources"); }); modelBuilder.Entity("DiunaBI.Domain.Entities.QueueJob", b => @@ -136,9 +136,6 @@ namespace DiunaBI.Infrastructure.Migrations .HasColumnType("datetime2") .HasDefaultValueSql("GETUTCDATE()"); - b.Property("CreatedAtUtc") - .HasColumnType("datetime2"); - b.Property("CreatedById") .HasColumnType("uniqueidentifier"); @@ -163,8 +160,10 @@ namespace DiunaBI.Infrastructure.Migrations b.Property("MaxRetries") .HasColumnType("int"); - b.Property("ModifiedAtUtc") - .HasColumnType("datetime2"); + b.Property("ModifiedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); b.Property("ModifiedById") .HasColumnType("uniqueidentifier"); @@ -185,7 +184,7 @@ namespace DiunaBI.Infrastructure.Migrations b.HasKey("Id"); - b.ToTable("QueueJobs", (string)null); + b.ToTable("QueueJobs"); }); modelBuilder.Entity("DiunaBI.Domain.Entities.Record", b => @@ -329,7 +328,7 @@ namespace DiunaBI.Infrastructure.Migrations b.HasIndex("ModifiedById"); - b.ToTable("Records", (string)null); + b.ToTable("Records"); }); modelBuilder.Entity("DiunaBI.Domain.Entities.RecordHistory", b => @@ -378,7 +377,7 @@ namespace DiunaBI.Infrastructure.Migrations b.HasIndex("RecordId", "ChangedAt"); - b.ToTable("RecordHistory", (string)null); + b.ToTable("RecordHistory"); }); modelBuilder.Entity("DiunaBI.Domain.Entities.User", b => @@ -402,7 +401,7 @@ namespace DiunaBI.Infrastructure.Migrations b.HasKey("Id"); - b.ToTable("Users", (string)null); + b.ToTable("Users"); }); modelBuilder.Entity("DiunaBI.Domain.Entities.Layer", b => diff --git a/DiunaBI.Infrastructure/Services/JobSchedulerService.cs b/DiunaBI.Infrastructure/Services/JobSchedulerService.cs index f4dc19b..06a77ad 100644 --- a/DiunaBI.Infrastructure/Services/JobSchedulerService.cs +++ b/DiunaBI.Infrastructure/Services/JobSchedulerService.cs @@ -85,10 +85,9 @@ public class JobSchedulerService MaxRetries = maxRetries, Status = JobStatus.Pending, CreatedAt = DateTime.UtcNow, - CreatedAtUtc = DateTime.UtcNow, - ModifiedAtUtc = DateTime.UtcNow, - CreatedById = Guid.Empty, // System user - ModifiedById = Guid.Empty + ModifiedAt = DateTime.UtcNow, + CreatedById = DiunaBI.Domain.Entities.User.AutoImportUserId, + ModifiedById = DiunaBI.Domain.Entities.User.AutoImportUserId }; _db.QueueJobs.Add(job); @@ -175,10 +174,9 @@ public class JobSchedulerService MaxRetries = maxRetries, Status = JobStatus.Pending, CreatedAt = DateTime.UtcNow, - CreatedAtUtc = DateTime.UtcNow, - ModifiedAtUtc = DateTime.UtcNow, - CreatedById = Guid.Empty, - ModifiedById = Guid.Empty + ModifiedAt = DateTime.UtcNow, + CreatedById = DiunaBI.Domain.Entities.User.AutoImportUserId, + ModifiedById = DiunaBI.Domain.Entities.User.AutoImportUserId }; _db.QueueJobs.Add(job); diff --git a/DiunaBI.Infrastructure/Services/JobWorkerService.cs b/DiunaBI.Infrastructure/Services/JobWorkerService.cs index 8c8f39a..cfd4f82 100644 --- a/DiunaBI.Infrastructure/Services/JobWorkerService.cs +++ b/DiunaBI.Infrastructure/Services/JobWorkerService.cs @@ -66,7 +66,8 @@ public class JobWorkerService : BackgroundService // Mark job as running job.Status = JobStatus.Running; job.LastAttemptAt = DateTime.UtcNow; - job.ModifiedAtUtc = DateTime.UtcNow; + job.ModifiedAt = DateTime.UtcNow; + job.ModifiedById = DiunaBI.Domain.Entities.User.AutoImportUserId; await db.SaveChangesAsync(stoppingToken); try @@ -114,7 +115,8 @@ public class JobWorkerService : BackgroundService job.Status = JobStatus.Completed; job.CompletedAt = DateTime.UtcNow; job.LastError = null; - job.ModifiedAtUtc = DateTime.UtcNow; + job.ModifiedAt = DateTime.UtcNow; + job.ModifiedById = DiunaBI.Domain.Entities.User.AutoImportUserId; _logger.LogInformation("JobWorker: Job {JobId} completed successfully", job.Id); @@ -131,7 +133,8 @@ public class JobWorkerService : BackgroundService // Capture full error details including inner exceptions job.LastError = GetFullErrorMessage(ex); - job.ModifiedAtUtc = DateTime.UtcNow; + job.ModifiedAt = DateTime.UtcNow; + job.ModifiedById = DiunaBI.Domain.Entities.User.AutoImportUserId; if (job.RetryCount >= job.MaxRetries) { @@ -157,7 +160,8 @@ public class JobWorkerService : BackgroundService // Increment retry count for next attempt job.RetryCount++; - job.ModifiedAtUtc = DateTime.UtcNow; + job.ModifiedAt = DateTime.UtcNow; + job.ModifiedById = DiunaBI.Domain.Entities.User.AutoImportUserId; } } finally