增加hangfire日志增长限制,移除hangfire默认账号密码,由用户自行设置。

master
jianweie code 7 months ago
parent 4c1f71bee0
commit 6cccc3c401

@ -149,6 +149,10 @@ namespace CoreCms.Net.Configuration
#region HangFire定时任务================================================================================
/// <summary>
/// HangFire默认访问路由地址
/// </summary>
public static readonly string HangFireRoutePrefix = AppSettingsHelper.GetContent("HangFire", "RoutePrefix");
/// <summary>
/// 登录账号
/// </summary>
public static readonly string HangFireLogin = AppSettingsHelper.GetContent("HangFire", "Login");
@ -156,6 +160,10 @@ namespace CoreCms.Net.Configuration
/// 登录密码
/// </summary>
public static readonly string HangFirePassWord = AppSettingsHelper.GetContent("HangFire", "PassWord");
/// <summary>
/// 已经完成的任务过期时间单位分钟默认10080,7天时间
/// </summary>
public static readonly int HangFireJobExpirationTimeOut = AppSettingsHelper.GetContent("HangFire", "JobExpirationTimeOut").ObjToInt(10080);
#endregion

@ -0,0 +1,51 @@
using Hangfire.States;
using Hangfire.Storage;
using System;
namespace CoreCms.Net.Web.WebApi.Infrastructure
{
/// <summary>
/// 已完成的job设置过期防止数据无限增长
/// </summary>
public class SucceededStateExpireHandler : IStateHandler
{
/// <summary>
/// 数据过期时间
/// </summary>
public TimeSpan JobExpirationTimeout;
/// <summary>
/// 完成的项目过期状态处理
/// </summary>
/// <param name="jobExpirationTimeout"></param>
public SucceededStateExpireHandler(int jobExpirationTimeout)
{
JobExpirationTimeout = TimeSpan.FromMinutes(jobExpirationTimeout);
}
/// <summary>
/// 状态名称
/// </summary>
public string StateName => SucceededState.StateName;
/// <summary>
/// 应用状态
/// </summary>
/// <param name="context"></param>
/// <param name="transaction"></param>
public void Apply(ApplyStateContext context, IWriteOnlyTransaction transaction)
{
context.JobExpirationTimeout = JobExpirationTimeout;
}
/// <summary>
/// 不应用状态
/// </summary>
/// <param name="context"></param>
/// <param name="transaction"></param>
public void Unapply(ApplyStateContext context, IWriteOnlyTransaction transaction)
{
}
}
}

@ -198,9 +198,12 @@ var hangfireOptions = new Hangfire.DashboardOptions
IsReadOnlyFunc = _ => false
};
app.UseHangfireDashboard("/job", hangfireOptions); //可以改变Dashboard的url
app.UseHangfireDashboard(AppSettingsConstVars.HangFireRoutePrefix, hangfireOptions); //可以改变Dashboard的url
HangfireDispose.HangfireService();
//设置hangfire定时任务过期时间
GlobalStateHandlers.Handlers.Add(new SucceededStateExpireHandler(AppSettingsConstVars.HangFireJobExpirationTimeOut));
#endregion
//使用 Session

@ -10,8 +10,10 @@
},
//
"HangFire": {
"Login": "CoreShop",
"PassWord": "oq9wfbdeasygj647v"
"RoutePrefix": "/job", //'/job'
"Login": "", //
"PassWord": "", //
"JobExpirationTimeOut": "10080" //10080,7
},
//Swagger访
"SwaggerConfig": {

@ -31,9 +31,8 @@
<br />
<span class="zhuyi">注意事项:</span><br />
<p>1、以上组件地址支持自定义调整投产环境下请及时修改或屏蔽投产环境下可删除此展示页面。</p>
<p>2、『Swagger接口文档』访问路径修改位置为【Startup.cs】文件第206行左右【代码c.RoutePrefix = "doc"】请将doc修改为其他虚拟路径。</p>
<p>3、『HangFire定时任务』面板路径修改位置为【Startup.cs】文件第256行左右【代码app.UseHangfireDashboard("/job", options);】请将job修改为其他虚拟路径。</p>
<p>4、『HangFire定时任务』初始登录账号密码均为【CoreShop】修改位置为【appsettings.json】文件代码中【HangFire】节点。</p>
<p>2、『Swagger接口文档』访问路径登录账号密码均自行设置修改位置为【appsettings.json】文件代码中【SwaggerConfig】节点。</p>
<p>4、『HangFire定时任务』访问路径登录账号密码均自行设置修改位置为【appsettings.json】文件代码中【HangFire】节点。</p>
<p>5、如果无法访问接口请检查【1、数据库配置是否正常】【2、Redis是否配置正常并可正常链接使用】【3、Mysql数据库请保持5.7+版本】【4、站点日志文件夹写入权限】。</p>
<p>6、如果第三方请求接口服务获取不到数据Debug提示【Access-Control-Allow-Origin】的错误表示为跨域问题请打开【appsettings.json】文件在【Cors】节点设置请求白名单。</p>
</div>

Loading…
Cancel
Save