using Hangfire;
using TakeoutSaaS.Module.Scheduler.Abstractions;
using TakeoutSaaS.Module.Scheduler.Jobs;

namespace TakeoutSaaS.Module.Scheduler.Services;

/// <summary>
/// 周期性任务注册器。
/// </summary>
public sealed class RecurringJobRegistrar : IRecurringJobRegistrar
{
    /// <inheritdoc />
    public Task RegisterAsync(CancellationToken cancellationToken = default)
    {
        RecurringJob.AddOrUpdate<OrderTimeoutJob>("orders.timeout-cancel", job => job.ExecuteAsync(), "*/5 * * * *");
        RecurringJob.AddOrUpdate<CouponExpireJob>("coupons.expire", job => job.ExecuteAsync(), "0 */1 * * *");
        RecurringJob.AddOrUpdate<LogCleanupJob>("logs.cleanup", job => job.ExecuteAsync(), "0 3 * * *");
        return Task.CompletedTask;
    }
}
