133 lines
4.9 KiB
C#
133 lines
4.9 KiB
C#
using System.Collections.Immutable;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace StellaOps.Scheduler.Models;
|
|
|
|
/// <summary>
|
|
/// Job that materializes or refreshes an overlay on top of an existing graph snapshot.
|
|
/// </summary>
|
|
public sealed record GraphOverlayJob
|
|
{
|
|
public GraphOverlayJob(
|
|
string id,
|
|
string tenantId,
|
|
string graphSnapshotId,
|
|
GraphOverlayKind overlayKind,
|
|
string overlayKey,
|
|
GraphJobStatus status,
|
|
GraphOverlayJobTrigger trigger,
|
|
DateTimeOffset createdAt,
|
|
IEnumerable<string>? subjects = null,
|
|
int attempts = 0,
|
|
string? buildJobId = null,
|
|
string? correlationId = null,
|
|
DateTimeOffset? startedAt = null,
|
|
DateTimeOffset? completedAt = null,
|
|
string? error = null,
|
|
IEnumerable<KeyValuePair<string, string>>? metadata = null,
|
|
string? schemaVersion = null)
|
|
: this(
|
|
id,
|
|
tenantId,
|
|
graphSnapshotId,
|
|
Validation.TrimToNull(buildJobId),
|
|
overlayKind,
|
|
Validation.EnsureNotNullOrWhiteSpace(overlayKey, nameof(overlayKey)),
|
|
Validation.NormalizeStringSet(subjects, nameof(subjects)),
|
|
status,
|
|
trigger,
|
|
Validation.EnsureNonNegative(attempts, nameof(attempts)),
|
|
Validation.TrimToNull(correlationId),
|
|
Validation.NormalizeTimestamp(createdAt),
|
|
Validation.NormalizeTimestamp(startedAt),
|
|
Validation.NormalizeTimestamp(completedAt),
|
|
Validation.TrimToNull(error),
|
|
Validation.NormalizeMetadata(metadata),
|
|
schemaVersion)
|
|
{
|
|
}
|
|
|
|
[JsonConstructor]
|
|
public GraphOverlayJob(
|
|
string id,
|
|
string tenantId,
|
|
string graphSnapshotId,
|
|
string? buildJobId,
|
|
GraphOverlayKind overlayKind,
|
|
string overlayKey,
|
|
ImmutableArray<string> subjects,
|
|
GraphJobStatus status,
|
|
GraphOverlayJobTrigger trigger,
|
|
int attempts,
|
|
string? correlationId,
|
|
DateTimeOffset createdAt,
|
|
DateTimeOffset? startedAt,
|
|
DateTimeOffset? completedAt,
|
|
string? error,
|
|
ImmutableSortedDictionary<string, string> metadata,
|
|
string? schemaVersion = null)
|
|
{
|
|
Id = Validation.EnsureId(id, nameof(id));
|
|
TenantId = Validation.EnsureTenantId(tenantId, nameof(tenantId));
|
|
GraphSnapshotId = Validation.EnsureId(graphSnapshotId, nameof(graphSnapshotId));
|
|
BuildJobId = Validation.TrimToNull(buildJobId);
|
|
OverlayKind = overlayKind;
|
|
OverlayKey = Validation.EnsureNotNullOrWhiteSpace(overlayKey, nameof(overlayKey));
|
|
Subjects = subjects.IsDefault ? ImmutableArray<string>.Empty : subjects;
|
|
Status = status;
|
|
Trigger = trigger;
|
|
Attempts = Validation.EnsureNonNegative(attempts, nameof(attempts));
|
|
CorrelationId = Validation.TrimToNull(correlationId);
|
|
CreatedAt = Validation.NormalizeTimestamp(createdAt);
|
|
StartedAt = Validation.NormalizeTimestamp(startedAt);
|
|
CompletedAt = Validation.NormalizeTimestamp(completedAt);
|
|
Error = Validation.TrimToNull(error);
|
|
var materializedMetadata = metadata ?? ImmutableSortedDictionary<string, string>.Empty;
|
|
Metadata = materializedMetadata.Count > 0
|
|
? materializedMetadata.WithComparers(StringComparer.Ordinal)
|
|
: ImmutableSortedDictionary<string, string>.Empty;
|
|
SchemaVersion = SchedulerSchemaVersions.EnsureGraphOverlayJob(schemaVersion);
|
|
}
|
|
|
|
public string SchemaVersion { get; }
|
|
|
|
public string Id { get; }
|
|
|
|
public string TenantId { get; }
|
|
|
|
public string GraphSnapshotId { get; }
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
public string? BuildJobId { get; init; }
|
|
|
|
public GraphOverlayKind OverlayKind { get; }
|
|
|
|
public string OverlayKey { get; }
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
|
public ImmutableArray<string> Subjects { get; } = ImmutableArray<string>.Empty;
|
|
|
|
public GraphJobStatus Status { get; init; }
|
|
|
|
public GraphOverlayJobTrigger Trigger { get; }
|
|
|
|
public int Attempts { get; init; }
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
public string? CorrelationId { get; init; }
|
|
|
|
public DateTimeOffset CreatedAt { get; }
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
public DateTimeOffset? StartedAt { get; init; }
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
public DateTimeOffset? CompletedAt { get; init; }
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
public string? Error { get; init; }
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
|
public ImmutableSortedDictionary<string, string> Metadata { get; } = ImmutableSortedDictionary<string, string>.Empty;
|
|
}
|