| | | 1 | | using Newtonsoft.Json; |
| | | 2 | | using Services.HangfireService.Models; |
| | | 3 | | |
| | | 4 | | namespace OzonOrdersWeb.WebServices.Hangfire; |
| | | 5 | | |
| | | 6 | | /// <summary>Строка грида очереди Hangfire: аргументы уже сериализованы, длительность — в миллисекундах.</summary> |
| | | 7 | | public sealed record HangfireJobGridRow( |
| | | 8 | | string? Id, |
| | | 9 | | string? Method, |
| | | 10 | | string? State, |
| | | 11 | | string? ServerId, |
| | | 12 | | DateTime? EnqueuedAt, |
| | | 13 | | DateTime? StartedAt, |
| | | 14 | | DateTime? SucceededAt, |
| | | 15 | | DateTime? DeletedAt, |
| | | 16 | | long? DurationMs, |
| | | 17 | | string? Args, |
| | | 18 | | string? Result); |
| | | 19 | | |
| | | 20 | | /// <summary>Вкладки очереди Hangfire (В очереди / Выполняются / Выполненные / Удалённые) → строки гридов.</summary> |
| | | 21 | | public static class HangfireJobGridRows |
| | | 22 | | { |
| | | 23 | | public const string Enqueued = "enqueued"; |
| | | 24 | | public const string Processing = "processing"; |
| | | 25 | | public const string Succeeded = "succeeded"; |
| | | 26 | | public const string Deleted = "deleted"; |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Для выполняющихся длительность считается от StartedAt до <paramref name="nowUtc"/>; для выполненных — из Hangfir |
| | | 30 | | /// </summary> |
| | | 31 | | public static List<HangfireJobGridRow> Build(string kind, IEnumerable<JobDto>? jobs, DateTime nowUtc) => |
| | 5 | 32 | | (jobs ?? []).Select(j => new HangfireJobGridRow( |
| | 5 | 33 | | j.Id, |
| | 5 | 34 | | j.MethodName, |
| | 5 | 35 | | j.State, |
| | 5 | 36 | | j.ServerId, |
| | 5 | 37 | | j.EnqueuedAt, |
| | 5 | 38 | | j.StartedAt, |
| | 5 | 39 | | j.SucceededAt, |
| | 5 | 40 | | j.DeletedAt, |
| | 5 | 41 | | kind == Processing |
| | 5 | 42 | | ? (long)Math.Max(0, (nowUtc - (j.StartedAt ?? nowUtc)).TotalMilliseconds) |
| | 5 | 43 | | : j.Duration, |
| | 5 | 44 | | j.Args != null ? JsonConvert.SerializeObject(j.Args, Formatting.Indented) : null, |
| | 5 | 45 | | string.IsNullOrEmpty(j.Result) ? null : j.Result)) |
| | 3 | 46 | | .ToList(); |
| | | 47 | | } |