Hangfire 指定redis db

master
wanghaomei 3 years ago
parent e7baaabadf
commit 919a8412e5

@ -33,9 +33,11 @@ namespace djyweb_djyPaasApi
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().ConfigureApiBehaviorOptions(options=> {
services.AddControllers().ConfigureApiBehaviorOptions(options =>
{
options.InvalidModelStateResponseFactory = context =>
{var result = new BadRequestObjectResult(context.HttpContext);
{
var result = new BadRequestObjectResult(context.HttpContext);
return result;
};
});
@ -46,7 +48,8 @@ namespace djyweb_djyPaasApi
Configuration.Bind("WebConfig", sysOptionConfig.YsWebconfig);
sysOptionConfig._Configuration = Configuration;
services.AddAuthentication("Bearer").AddJwtBearer("Bearer",option=> {
services.AddAuthentication("Bearer").AddJwtBearer("Bearer", option =>
{
option.Authority = sysOptionConfig.YsWebconfig.IdentServerUrl;//授权服务的URl地址
option.RequireHttpsMetadata = false;//是否使用了https
option.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
@ -73,8 +76,9 @@ namespace djyweb_djyPaasApi
services.AddAutoMapper(typeof(AutoMapperConfig));
//任务配置
services.AddHangfire(config => {
config.UseRedisStorage(sysOptionConfig.YsWebconfig.Redis, new Hangfire.Redis.RedisStorageOptions { Prefix = "hf_"+sysOptionConfig.YsWebconfig.WebName,InvisibilityTimeout=TimeSpan.FromHours(1) });
services.AddHangfire(config =>
{
config.UseRedisStorage(sysOptionConfig.YsWebconfig.Redis, new Hangfire.Redis.RedisStorageOptions { Prefix = "hf_" + sysOptionConfig.YsWebconfig.WebName, InvisibilityTimeout = TimeSpan.FromHours(1), Db = 3 });
});
services.AddHangfireServer();
@ -105,7 +109,7 @@ namespace djyweb_djyPaasApi
c.SwaggerDoc("v1", new OpenApiInfo { Title = "web_djyPaasapi", Version = "v1" });
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
var xmlPath = Path.Combine(basePath, "AppServer.xml");
// c.IncludeXmlComments(Path.Combine(basePath, "djyweb_djyPaasApi.xml"));
// c.IncludeXmlComments(Path.Combine(basePath, "djyweb_djyPaasApi.xml"));
//c.IncludeXmlComments(Path.Combine(basePath, "djy.Model.xml"));
//c.IncludeXmlComments(Path.Combine(basePath, "Ys.Core.Common.xml"));
});
@ -127,10 +131,11 @@ namespace djyweb_djyPaasApi
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => {
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "web_djyuserapi v1");
// c.RoutePrefix = "apidoc";
// c.RoutePrefix = "apidoc";
});
}
@ -145,7 +150,8 @@ namespace djyweb_djyPaasApi
app.UseDefaultFiles(defaultFiles);
app.UseStaticFiles();
app.UseCors(builder => {
app.UseCors(builder =>
{
builder.AllowAnyHeader();
builder.AllowAnyMethod();
//builder.WithOrigins("http://www.baidu.com");//跨域配置
@ -155,13 +161,13 @@ namespace djyweb_djyPaasApi
app.UseAuthorization();//授权
app.UseHangfireDashboard("/job", new DashboardOptions() { Authorization = new[] { new HangFireAuthorizeFilter() } });
app.UseHangfireDashboard("/job", new DashboardOptions() { Authorization = new[] { new HangFireAuthorizeFilter() } });
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
});
//启动运行启动
_Job(env);
@ -170,14 +176,15 @@ namespace djyweb_djyPaasApi
/// <summary>
/// 启动任务请求
/// </summary>
private void _Job(IWebHostEnvironment env) {
private void _Job(IWebHostEnvironment env)
{
//初始化数据字典
var _itool = IOC.AddServer<IToolsService>();
_itool.bindConfigDict(true, 5);
_itool.AutoJob();
_itool.AutoJob();
}

Loading…
Cancel
Save