using Hangfire;
using Hangfire.SqlServer;
using Hangfire.Tags.SqlServer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace IRaCIS.Core.API
{
    public  static class hangfireSetup
    {
        public static void AddhangfireSetup(this IServiceCollection services, IConfiguration configuration)
        {
            var hangFireConnStr = configuration.GetSection("ConnectionStrings:Hangfire").Value;

            services.AddHangfire(hangFireConfig =>
            {
                //指定存储介质
                hangFireConfig.UseSqlServerStorage(hangFireConnStr, new SqlServerStorageOptions()
                {
                    SchemaName = "hangfire",
                    CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                    SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                    QueuePollInterval = TimeSpan.Zero,
                    UseRecommendedIsolationLevel = true,
                    UsePageLocksOnDequeue = true,
                    DisableGlobalLocks = true
                });

                hangFireConfig.UseTagsWithSql(); //nuget引入Hangfire.Tags.SqlServer
                //.UseHangfireHttpJob();

            });

            services.AddHangfireServer();

        }
    }
}
