feat(api,core,dal,domain): Сохранение снапшотов состояния роботов.

This commit is contained in:
Mikhail Trubnikov
2026-06-10 16:48:16 +10:00
parent a64ab59de1
commit d736208a46
22 changed files with 4194 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ using PARR.Domain.Common.Roles;
using PARR.Domain.Common.Template;
using PARR.Domain.Entities;
using PARR.Domain.Entities.Job;
using PARR.Domain.Entities.RobotEntities;
using PARR.Domain.Entities.Schedule;
using PARR.Domain.Entities.TaskEntities;
using PARR.Domain.Entities.Unit;
@@ -126,6 +127,12 @@ namespace PARR.DAL.Context
#endregion
#region Robot
public DbSet<RobotSnapshot> RobotSnapshots { get; set; }
#endregion
protected override void OnModelCreating(ModelBuilder modelBuilder)
{

View File

@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PARR.Core.Repositories.Interfaces;
using PARR.Core.Repositories.Interfaces.Job;
using PARR.Core.Repositories.Interfaces.RobotRepositories;
using PARR.Core.Repositories.Interfaces.Schedule;
using PARR.Core.Repositories.Interfaces.TaskRepositories;
using PARR.Core.Repositories.Interfaces.Unit;
@@ -11,6 +12,7 @@ using PARR.DAL.Configurations.DbSettings;
using PARR.DAL.Context;
using PARR.DAL.Repositories;
using PARR.DAL.Repositories.Job;
using PARR.DAL.Repositories.RobotRepositories;
using PARR.DAL.Repositories.Schedule;
using PARR.DAL.Repositories.TaskRepositories;
using PARR.DAL.Repositories.Unit;
@@ -79,6 +81,9 @@ namespace PARR.DAL
services.AddTransient<IParrComponentRepository, ParrComponentRepository>();
services.AddTransient<ITemplateStatusTypeRepository, TemplateStatusTypeRepository>();
services.AddScoped<IRobotSnapshotRepository, RobotSnapshotRepository>();
#region Schedule
services.AddTransient<IScheduleExcludeTypeRepository, ScheduleExcludeTypeRepository>();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,64 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class tblRobotSnapshot : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "robot");
migrationBuilder.CreateTable(
name: "Snapshots",
schema: "robot",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
TemplateRobotsCount = table.Column<int>(type: "integer", nullable: false, comment: "Количество запущенных роботов по шаблонам"),
ScheduleRobotsCount = table.Column<int>(type: "integer", nullable: false, comment: "Количество запущенных роботов по расписаниям"),
MaxRobots = table.Column<int>(type: "integer", nullable: false, comment: "Максимально разрешенное количество роботов на сервере"),
Ip = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: false, comment: "Текущий IP-адрес сервера")
},
constraints: table =>
{
table.PrimaryKey("PK_Snapshots", x => x.Id);
},
comment: "Снимки роботов");
migrationBuilder.UpdateData(
table: "Settings",
keyColumn: "Name",
keyValue: "RobotWaitTime",
column: "Value",
value: "00:10:00");
migrationBuilder.CreateIndex(
name: "IX_Snapshots_Ip_DateCreated",
schema: "robot",
table: "Snapshots",
columns: new[] { "Ip", "DateCreated" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Snapshots",
schema: "robot");
migrationBuilder.UpdateData(
table: "Settings",
keyColumn: "Name",
keyValue: "RobotWaitTime",
column: "Value",
value: "00:15:00");
}
}
}

View File

@@ -867,6 +867,43 @@ namespace PARR.DAL.Migrations
b.ToTable("RobotConfigurations");
});
modelBuilder.Entity("PARR.Domain.Entities.RobotEntities.RobotSnapshot", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<string>("Ip")
.IsRequired()
.HasMaxLength(45)
.HasColumnType("character varying(45)")
.HasComment("Текущий IP-адрес сервера");
b.Property<int>("MaxRobots")
.HasColumnType("integer")
.HasComment("Максимально разрешенное количество роботов на сервере");
b.Property<int>("ScheduleRobotsCount")
.HasColumnType("integer")
.HasComment("Количество запущенных роботов по расписаниям");
b.Property<int>("TemplateRobotsCount")
.HasColumnType("integer")
.HasComment("Количество запущенных роботов по шаблонам");
b.HasKey("Id");
b.HasIndex("Ip", "DateCreated");
b.ToTable("Snapshots", "robot", t =>
{
t.HasComment("Снимки роботов");
});
});
modelBuilder.Entity("PARR.Domain.Entities.RobotHistory", b =>
{
b.Property<Guid>("Id")
@@ -2261,7 +2298,7 @@ namespace PARR.DAL.Migrations
{
Name = "RobotWaitTime",
Description = "Время ожидания выполнения роботом задания",
Value = "00:15:00"
Value = "00:10:00"
},
new
{

View File

@@ -0,0 +1,13 @@
using Microsoft.Extensions.Logging;
using PARR.Core.Repositories.Interfaces.RobotRepositories;
using PARR.DAL.Context;
using PARR.DAL.Repositories.Base;
using PARR.Domain.Entities.RobotEntities;
namespace PARR.DAL.Repositories.RobotRepositories
{
internal class RobotSnapshotRepository : BaseRepository<RobotSnapshot>, IRobotSnapshotRepository
{
public RobotSnapshotRepository(ILogger<RobotSnapshotRepository> logger, DataContext dataContext) : base(logger, dataContext) { }
}
}