using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using TakeoutSaaS.Module.Scheduler.Abstractions;

namespace TakeoutSaaS.Module.Scheduler.HostedServices;

/// <summary>
/// 启动时注册周期性任务的宿主服务。
/// </summary>
public sealed class RecurringJobHostedService(IRecurringJobRegistrar registrar, ILogger<RecurringJobHostedService> logger) : IHostedService
{
    /// <inheritdoc />
    public async Task StartAsync(CancellationToken cancellationToken)
    {
        await registrar.RegisterAsync(cancellationToken).ConfigureAwait(false);
        logger.LogInformation("调度任务已注册");
    }

    /// <inheritdoc />
    public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
