using Hangfire;
using Hangfire.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.UseInMemoryStorage();

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

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

            });

            services.AddHangfireServer(option =>
            {
                option.Queues = new[] { "immediately_once","default","sys_init" , "not_immediately_once" };
            });

        }
    }
}
