41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
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 = "hangfire",
|
|
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
|
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
|
QueuePollInterval = TimeSpan.Zero,
|
|
UseRecommendedIsolationLevel = true,
|
|
DisableGlobalLocks = true
|
|
});
|
|
|
|
//hangFireConfig.UseTagsWithSql(); //nuget引入Hangfire.Tags.SqlServer
|
|
//.UseHangfireHttpJob();
|
|
|
|
});
|
|
|
|
services.AddHangfireServer();
|
|
|
|
}
|
|
}
|
|
}
|