diff --git a/CoreCms.Net.Configuration/AppSettingsConstVars.cs b/CoreCms.Net.Configuration/AppSettingsConstVars.cs
index 71eee4b..e571648 100644
--- a/CoreCms.Net.Configuration/AppSettingsConstVars.cs
+++ b/CoreCms.Net.Configuration/AppSettingsConstVars.cs
@@ -149,6 +149,10 @@ namespace CoreCms.Net.Configuration
#region HangFire定时任务================================================================================
///
+ /// HangFire默认访问路由地址
+ ///
+ public static readonly string HangFireRoutePrefix = AppSettingsHelper.GetContent("HangFire", "RoutePrefix");
+ ///
/// 登录账号
///
public static readonly string HangFireLogin = AppSettingsHelper.GetContent("HangFire", "Login");
@@ -156,6 +160,10 @@ namespace CoreCms.Net.Configuration
/// 登录密码
///
public static readonly string HangFirePassWord = AppSettingsHelper.GetContent("HangFire", "PassWord");
+ ///
+ /// 已经完成的任务过期时间,单位分钟(默认10080,7天时间)
+ ///
+ public static readonly int HangFireJobExpirationTimeOut = AppSettingsHelper.GetContent("HangFire", "JobExpirationTimeOut").ObjToInt(10080);
#endregion
diff --git a/CoreCms.Net.Web.WebApi/Infrastructure/SucceededStateExpireHandler.cs b/CoreCms.Net.Web.WebApi/Infrastructure/SucceededStateExpireHandler.cs
new file mode 100644
index 0000000..3360e5d
--- /dev/null
+++ b/CoreCms.Net.Web.WebApi/Infrastructure/SucceededStateExpireHandler.cs
@@ -0,0 +1,51 @@
+using Hangfire.States;
+using Hangfire.Storage;
+using System;
+
+namespace CoreCms.Net.Web.WebApi.Infrastructure
+{
+ ///
+ /// 已完成的job设置过期,防止数据无限增长
+ ///
+ public class SucceededStateExpireHandler : IStateHandler
+ {
+ ///
+ /// 数据过期时间
+ ///
+ public TimeSpan JobExpirationTimeout;
+
+ ///
+ /// 完成的项目过期状态处理
+ ///
+ ///
+ public SucceededStateExpireHandler(int jobExpirationTimeout)
+ {
+ JobExpirationTimeout = TimeSpan.FromMinutes(jobExpirationTimeout);
+ }
+
+ ///
+ /// 状态名称
+ ///
+ public string StateName => SucceededState.StateName;
+
+ ///
+ /// 应用状态
+ ///
+ ///
+ ///
+ public void Apply(ApplyStateContext context, IWriteOnlyTransaction transaction)
+ {
+ context.JobExpirationTimeout = JobExpirationTimeout;
+ }
+
+ ///
+ /// 不应用状态
+ ///
+ ///
+ ///
+ public void Unapply(ApplyStateContext context, IWriteOnlyTransaction transaction)
+ {
+ }
+ }
+
+}
diff --git a/CoreCms.Net.Web.WebApi/Program.cs b/CoreCms.Net.Web.WebApi/Program.cs
index 60c0691..c9e8d8c 100644
--- a/CoreCms.Net.Web.WebApi/Program.cs
+++ b/CoreCms.Net.Web.WebApi/Program.cs
@@ -198,9 +198,12 @@ var hangfireOptions = new Hangfire.DashboardOptions
IsReadOnlyFunc = _ => false
};
-app.UseHangfireDashboard("/job", hangfireOptions); //ԸıDashboardurl
+app.UseHangfireDashboard(AppSettingsConstVars.HangFireRoutePrefix, hangfireOptions); //ԸıDashboardurl
HangfireDispose.HangfireService();
+//hangfireʱʱ
+GlobalStateHandlers.Handlers.Add(new SucceededStateExpireHandler(AppSettingsConstVars.HangFireJobExpirationTimeOut));
+
#endregion
//ʹ Session
diff --git a/CoreCms.Net.Web.WebApi/appsettings.json b/CoreCms.Net.Web.WebApi/appsettings.json
index 4c5599f..9074434 100644
--- a/CoreCms.Net.Web.WebApi/appsettings.json
+++ b/CoreCms.Net.Web.WebApi/appsettings.json
@@ -10,8 +10,10 @@
},
//定时任务管理面板的账户密码
"HangFire": {
- "Login": "CoreShop",
- "PassWord": "oq9wfbdeasygj647v"
+ "RoutePrefix": "/job", //路由地址,默认'/job'
+ "Login": "", //登录账号
+ "PassWord": "", //登录密码
+ "JobExpirationTimeOut": "10080" //已经完成的任务过期时间,单位分钟(默认10080,7天时间)
},
//Swagger授权访问设置
"SwaggerConfig": {
diff --git a/CoreCms.Net.Web.WebApi/wwwroot/index.html b/CoreCms.Net.Web.WebApi/wwwroot/index.html
index b2755e0..df44ca2 100644
--- a/CoreCms.Net.Web.WebApi/wwwroot/index.html
+++ b/CoreCms.Net.Web.WebApi/wwwroot/index.html
@@ -31,9 +31,8 @@
注意事项:
1、以上组件地址支持自定义调整,投产环境下请及时修改或屏蔽;投产环境下可删除此展示页面。
- 2、『Swagger接口文档』访问路径修改位置为:【Startup.cs】文件第206行左右【代码:c.RoutePrefix = "doc"】,请将doc修改为其他虚拟路径。
- 3、『HangFire定时任务』面板路径修改位置为:【Startup.cs】文件第256行左右【代码:app.UseHangfireDashboard("/job", options);】,请将job修改为其他虚拟路径。
- 4、『HangFire定时任务』初始登录账号密码均为:【CoreShop】,修改位置为:【appsettings.json】文件,代码中【HangFire】节点。
+ 2、『Swagger接口文档』访问路径,登录账号密码均自行设置,修改位置为:【appsettings.json】文件,代码中【SwaggerConfig】节点。
+ 4、『HangFire定时任务』访问路径,登录账号密码均自行设置,修改位置为:【appsettings.json】文件,代码中【HangFire】节点。
5、如果无法访问接口,请检查【1、数据库配置是否正常】【2、Redis是否配置正常并可正常链接使用】【3、Mysql数据库请保持5.7+版本】【4、站点日志文件夹写入权限】。
6、如果第三方请求接口服务获取不到数据,Debug提示【Access-Control-Allow-Origin】的错误,表示为跨域问题,请打开【appsettings.json】文件在【Cors】节点设置请求白名单。