You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using Hangfire;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Hangfire.MySql;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Transactions;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
|
|
|
|
namespace BackGround
|
|
|
|
|
{
|
|
|
|
|
public static class HangfireInjection
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection IntegrateHangfire(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
services.AddHangfire(config =>
|
|
|
|
|
{
|
|
|
|
|
config.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
|
|
|
|
.UseSimpleAssemblyNameTypeSerializer()
|
|
|
|
|
.UseRecommendedSerializerSettings()
|
|
|
|
|
.UseStorage(new MySqlStorage(
|
|
|
|
|
configuration.GetConnectionString("default"),
|
|
|
|
|
new MySqlStorageOptions
|
|
|
|
|
{
|
|
|
|
|
TransactionIsolationLevel = IsolationLevel.ReadCommitted, // 事务隔离级别。默认是读取已提交。
|
|
|
|
|
QueuePollInterval = TimeSpan.FromSeconds(15), //- 作业队列轮询间隔。默认值为15秒。
|
|
|
|
|
JobExpirationCheckInterval = TimeSpan.FromHours(1), //- 作业到期检查间隔(管理过期记录)。默认值为1小时。
|
|
|
|
|
CountersAggregateInterval = TimeSpan.FromMinutes(5), //- 聚合计数器的间隔。默认为5分钟。
|
|
|
|
|
PrepareSchemaIfNecessary = true, //- 如果设置为true,则创建数据库表。默认是true。
|
|
|
|
|
DashboardJobListLimit = 50000, //- 仪表板作业列表限制。默认值为50000。
|
|
|
|
|
TransactionTimeout = TimeSpan.FromMinutes(1), //- 交易超时。默认为1分钟 //- 数据库中表的前缀。默认为none
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
services.AddHangfireServer(opt => opt.WorkerCount = 10);
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|