Added job interruption handling

This commit is contained in:
Khwezi Mngoma
2026-06-03 10:40:29 +02:00
parent 4bac14881d
commit a0cf847e51
7 changed files with 71 additions and 31 deletions
+17 -6
View File
@@ -21,17 +21,28 @@ public sealed class MediatorJob<TNotification>(IMediator mediator) : IJob where
if (notification is null)
{
Trace.WriteLine("Notification could not be JSon converted from data string, job ended");
Trace.WriteLine("Notification could not be Json converted from data string, job ended");
return;
}
using var activity = MediatorTelemetry.Source.StartActivity($"Quartz: {typeof(TNotification).Name}");
using var activity = MediatorTelemetry.Source.StartActivity(typeof(TNotification).Name);
activity?.SetTag("event.correlation_id", notification.CorrelationId);
await mediator.Publish(notification, context.CancellationToken);
try
{
await mediator.Publish(notification, context.CancellationToken);
Trace.WriteLine("Job published");
Trace.WriteLine("Job published successfully");
}
catch (OperationCanceledException) when (context.CancellationToken.IsCancellationRequested)
{
Trace.WriteLine($"Job '{typeof(TNotification).Name}' was gracefully interrupted by the cluster control plane.");
activity?.SetStatus(ActivityStatusCode.Ok);
return;
}
}
}