namespace DS.Module.HangfireModule;
using DS.Module.Core;
using Hangfire;
using Hangfire.HttpJob;
using Hangfire.MySql;
using Microsoft.Extensions.DependencyInjection;
using System.Transactions;
///
/// 注入Hangfire服务
///
public static class HangfireModuleInstall
{
///
///
///
///
///
public static void AddHangfireModuleInstall(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseStorage(new MySqlStorage(
AppSetting.app(new string[] { "DBInfo", "HangfireDbString" }),
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分钟。
TablesPrefix = "Hangfire"
})).UseHangfireHttpJob());
//services.AddHangfireServer();
services.AddHangfireServer(options =>
{
options.Queues = new[] { "op", "default" };
});
}
}