Files
Chronos/src/Chronos.Server/Api/Dto.cs
T
Alby96andClaude Opus 5.5 ee9505df22 feat(jobs): progress detail contract and a 2/s publish throttle
Mass passes need to say what they do now (photo x of y, sequence n of m) without
slowing down. This adds the contract and the engine side; handlers and displays
follow in their own parcels.

- Core: JobDetail (step, item, item x of y, part n of m with unit), JobStep and
  JobPartUnit appended-only and stored by kebab name; Job.Detail.
- Protocol: JobDetailDto, appended as JobDto.Detail, JobProgressEvent.Detail and
  NodeProgress.Detail, so older peers ignore it and newer ones fall back.
- Data: JobContext keeps a detail across reports (ReportAsync with a detail,
  ReportItemAsync without allocating, CheckpointAsync with a detail) and publishes
  at most once per ProgressInterval (500 ms on the engine's TimeProvider), at once
  for the first report, a new step or a completed count; a dropped report costs no
  allocation or lock, and the persist that falls due publishes what it saves.
  Persist stays at most every 5 s. JobWire maps steps, units and details; an
  unknown name reads as none.
- Migration 0011 adds jobs.progress_detail (nullable JSON text); an unreadable
  cell reads as no detail. Lists return it.
- Server: ProgressGate (500 ms per job, step-change and completion bypass)
  shared by the engine host and render nodes; node details are stored and
  broadcast, an older node without one still works.

Refs #65

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 13:02:59 +01:00

53 lines
2.6 KiB
C#

using System.Text.Json;
using Chronos.Core.Model;
using Chronos.Data.Jobs;
using Chronos.Protocol;
namespace Chronos.Server.Api;
/// <summary>Domain entities → API v1 contracts.</summary>
public static class Dto
{
public static UserDto User(User u) => new(
u.Id, u.Username, u.DisplayName, Role(u.Role), (long)u.Permissions, u.QuotaBytes, u.UsedBytes, u.Disabled, u.MustChangePassword,
u.Created, u.LastLogin);
public static string Role(UserRole role) => role.ToString().ToLowerInvariant();
public static SequenceDto Sequence(Sequence s) => new(
s.Id, s.Title, s.DisplayTitle, s.Folder, s.CameraMake, s.CameraModel, s.Lens, s.FirstCapture, s.LastCapture, s.FrameCount,
s.MedianInterval, s.TotalBytes, (long)s.Status, s.RenderedCount, s.HeroFrameId, s.Tags, s.Rating, s.Notes, s.SettingsVersion,
s.FramesVersion, s.WarningCount, s.OwnerUserId, s.UpdatedAt, s.PreviewOnlyCount);
public static FrameDto Frame(Frame f) => new(
f.Id, f.SequenceId, f.Index, f.FileName, f.Size, f.Sha256, f.CapturedAt, f.UtcOffsetMinutes, f.ExposureTime, f.FNumber, f.Iso,
f.FocalLength, f.Orientation, f.Width, f.Height, f.Format.ToString().ToLowerInvariant(), (long)f.Flags, f.PreviewWidth, f.PreviewHeight);
public static RenderDto Render(Render r) => new(r.Id, r.PresetName, r.Codec, r.Width, r.Height, r.Fps, r.DurationSeconds, r.Bytes, r.Created, r.ProducedBy,
r.ProjectId, r.ProjectVersionId, r.Sha256, r.Kind);
public static JobDto Job(Job j) => new(
j.Id, JobWire.Kind(j.Kind), j.TargetIds, j.TargetLabel, JobWire.State(j.State), JobWire.Priority(j.Priority), j.ProgressDone,
j.ProgressTotal, j.ItemsPerSecond, j.Eta?.TotalSeconds, j.LogTail, j.NodeId, j.Attempts, j.Error, j.Created, j.Started, j.Finished,
j.ScheduleId, JobWire.Detail(j.Detail));
public static AuditEntryDto Audit(AuditEntry a) => new(a.Id, a.At, a.UserId, a.Username, a.Action, a.TargetKind, a.TargetId, a.Details, a.RemoteAddress);
public static RenderNodeDto Node(RenderNode node, string username) =>
new(node.Id, node.ClientName, username, Capabilities(node)?.Encoders ?? [], node.LastHeartbeat, node.State);
/// <summary>What a node announced at registration (stored as its capabilities JSON).</summary>
public static RegisterNodeRequest? Capabilities(RenderNode node)
{
if (node.CapabilitiesJson is null) return null;
try
{
return JsonSerializer.Deserialize(node.CapabilitiesJson, ProtocolJson.Default.RegisterNodeRequest);
}
catch (JsonException)
{
return null;
}
}
}