45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
|
|
using StellaOps.Scheduler.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace StellaOps.Scheduler.WebService.GraphJobs.Events;
|
|
|
|
internal static class GraphJobEventFactory
|
|
{
|
|
public static GraphJobCompletedEvent Create(GraphJobCompletionNotification notification)
|
|
{
|
|
var eventId = Guid.CreateVersion7().ToString("n");
|
|
var attributes = new Dictionary<string, string>(StringComparer.Ordinal);
|
|
|
|
if (!string.IsNullOrWhiteSpace(notification.CorrelationId))
|
|
{
|
|
attributes["correlationId"] = notification.CorrelationId!;
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(notification.Error))
|
|
{
|
|
attributes["error"] = notification.Error!;
|
|
}
|
|
|
|
var payload = new GraphJobCompletedPayload
|
|
{
|
|
JobType = notification.JobType.ToString().ToLowerInvariant(),
|
|
Status = notification.Status,
|
|
OccurredAt = notification.OccurredAt,
|
|
Job = notification.Job,
|
|
ResultUri = notification.ResultUri
|
|
};
|
|
|
|
return new GraphJobCompletedEvent
|
|
{
|
|
EventId = eventId,
|
|
Kind = GraphJobEventKinds.GraphJobCompleted,
|
|
Tenant = notification.TenantId,
|
|
Timestamp = notification.OccurredAt,
|
|
Payload = payload,
|
|
Attributes = attributes.Count == 0 ? null : attributes
|
|
};
|
|
}
|
|
}
|