HRM-10/HRM.UI/Realtime/Jobs/JobSnapshot.cs
2026-11-30 13:35:21 +06:00

66 lines
2.2 KiB
C#

using System;
namespace HRM.UI.Realtime.Jobs
{
public enum JobStatus
{
Queued = 1,
Running = 2,
Succeeded = 3,
Failed = 4
}
/// <summary>Who besides the owner may watch a job.</summary>
public enum JobAudience
{
/// <summary>Only the user who started it.</summary>
Owner = 1,
/// <summary>Every user of the same payroll type (e.g. a second admin opening the Salary Process screen).</summary>
PayrollType = 2
}
/// <summary>
/// A job as the browser sees it - one immutable copy per message. Sent over SignalR and returned by api/jobs,
/// always with the same shape (Angular model: src/app/_models/realtime/job-snapshot.ts).
/// </summary>
public class JobSnapshot
{
public string RunId { get; set; }
/// <summary>The job's kind + scope, e.g. "salary-process:3". Only one job per key runs at a time.</summary>
public string Key { get; set; }
public string Title { get; set; }
public JobStatus Status { get; set; }
/// <summary>0 - 100, never goes backwards.</summary>
public double Percent { get; set; }
public string Stage { get; set; }
public string Detail { get; set; }
public int? Current { get; set; }
public int? Total { get; set; }
public DateTime QueuedAt { get; set; }
public DateTime? StartedAt { get; set; }
public DateTime? FinishedAt { get; set; }
public double ElapsedSeconds { get; set; }
/// <summary>Estimated seconds left, from the speed measured so far. Null until there is enough to measure.</summary>
public double? EtaSeconds { get; set; }
/// <summary>Grows with every change. A browser ignores a message older than the one it already shows.</summary>
public long Sequence { get; set; }
/// <summary>What the work returned (set when Succeeded). Its shape is the job's own business.</summary>
public object Result { get; set; }
/// <summary>Why it failed (set when Failed).</summary>
public string Error { get; set; }
public bool IsFinished => Status == JobStatus.Succeeded || Status == JobStatus.Failed;
}
}