【优化】优化定时任务组件HangFire初始化配置方式。

pull/123/head
JianWeie 3 years ago
parent db4e141a67
commit 7774f38c1a

@ -58,6 +58,16 @@ namespace CoreCms.Net.Core.Config
services.AddHangfire(x => x.UseSqlServerStorage(AppSettingsConstVars.DbSqlConnection));
}
}
services.AddHangfireServer(options =>
{
options.Queues = new[] { GlobalEnumVars.HangFireQueuesConfig.@default.ToString(), GlobalEnumVars.HangFireQueuesConfig.apis.ToString(), GlobalEnumVars.HangFireQueuesConfig.web.ToString(), GlobalEnumVars.HangFireQueuesConfig.recurring.ToString() };
options.ServerTimeout = TimeSpan.FromMinutes(4);
options.SchedulePollingInterval = TimeSpan.FromSeconds(15);//秒级任务需要配置短点一般任务可以配置默认时间默认15秒
options.ShutdownTimeout = TimeSpan.FromMinutes(30); //超时时间
options.WorkerCount = Math.Max(Environment.ProcessorCount, 20); //工作线程数当前允许的最大线程默认20
});
}
}
}

@ -205,16 +205,6 @@ namespace CoreCms.Net.Web.WebApi
#region Hangfire定时任务
var queues = new string[] { GlobalEnumVars.HangFireQueuesConfig.@default.ToString(), GlobalEnumVars.HangFireQueuesConfig.apis.ToString(), GlobalEnumVars.HangFireQueuesConfig.web.ToString(), GlobalEnumVars.HangFireQueuesConfig.recurring.ToString() };
app.UseHangfireServer(new BackgroundJobServerOptions
{
ServerTimeout = TimeSpan.FromMinutes(4),
SchedulePollingInterval = TimeSpan.FromSeconds(15),//秒级任务需要配置短点一般任务可以配置默认时间默认15秒
ShutdownTimeout = TimeSpan.FromMinutes(30),//超时时间
Queues = queues,//队列
WorkerCount = Math.Max(Environment.ProcessorCount, 20)//工作线程数当前允许的最大线程默认20
});
//授权
var filter = new BasicAuthAuthorizationFilter(
new BasicAuthAuthorizationFilterOptions

Loading…
Cancel
Save