22 lines
644 B
C#
22 lines
644 B
C#
using LiteCharms.Features.Abstractions;
|
|
|
|
namespace LiteCharms.Features.Quartz;
|
|
|
|
[DisallowConcurrentExecution]
|
|
public class MediatorJob<TNotification>(IMediator mediator) : IJob where TNotification : IEvent
|
|
{
|
|
public async Task Execute(IJobExecutionContext context)
|
|
{
|
|
var data = context.MergedJobDataMap["Payload"] as string;
|
|
|
|
if (string.IsNullOrWhiteSpace(data)) return;
|
|
|
|
var notification = JsonSerializer.Deserialize<TNotification>(data);
|
|
|
|
if(notification is null) return;
|
|
|
|
if(notification is TNotification)
|
|
await mediator.Publish(notification, context.CancellationToken);
|
|
}
|
|
}
|