#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Scheduling.Notifications;
using Lumina.Contracts.Responses.Scheduling;
using Microsoft.AspNetCore.SignalR;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Infrastructure.Core.Scheduling.Notifications;
///
/// Class used to notify SignalR clients about the scheduled jobs and their executions.
///
public sealed class ScheduledJobNotifier : IScheduledJobNotifier
{
private readonly IHubContext _hubContext;
///
/// Initializes a new instance of the class.
///
/// SignalR hub context abstraction.
public ScheduledJobNotifier(IHubContext hubContext)
{
_hubContext = hubContext;
}
///
/// Notifies the SignalR clients about the current list of scheduled jobs.
///
/// The current list of scheduled jobs.
/// Cancellation token that can be used to stop the execution.
public async Task SendScheduledJobsAsync(IReadOnlyList scheduledJobs, CancellationToken cancellationToken)
{
await _hubContext.Clients.All.ReceiveScheduledJobsAsync(scheduledJobs).ConfigureAwait(false);
}
///
/// Notifies the SignalR clients about an execution of the task of a scheduled job that started.
///
/// The execution of the task of the scheduled job that started.
/// Cancellation token that can be used to stop the execution.
public async Task SendScheduledJobExecutionStartedAsync(ScheduledJobExecutionResponse execution, CancellationToken cancellationToken)
{
await _hubContext.Clients.All.ScheduledJobExecutionStartedAsync(execution).ConfigureAwait(false);
}
///
/// Notifies the SignalR clients about an execution of the task of a scheduled job that completed.
///
/// The execution of the task of the scheduled job that completed.
/// Cancellation token that can be used to stop the execution.
public async Task SendScheduledJobExecutionCompletedAsync(ScheduledJobExecutionResponse execution, CancellationToken cancellationToken)
{
await _hubContext.Clients.All.ScheduledJobExecutionCompletedAsync(execution).ConfigureAwait(false);
}
}