【新增】hangfire定时任务增加【已经完成的Job任务进行定时过期删除处理】。

This commit is contained in:
jianweie code
2024-01-04 22:28:19 +08:00
parent 40449e092a
commit dd6eb11c96
5 changed files with 98 additions and 3 deletions

View File

@@ -119,6 +119,10 @@ namespace CoreCms.Net.Configuration
/// 登录密码 /// 登录密码
/// </summary> /// </summary>
public static readonly string HangFirePassWord = AppSettingsHelper.GetContent("HangFire", "PassWord"); 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 #endregion
@@ -146,7 +150,7 @@ namespace CoreCms.Net.Configuration
#endregion #endregion
#region Swagger授权访问设置================================================================================ #region Swagger授权访问设置
/// <summary> /// <summary>
/// Swagger文档默认访问路由地址 /// Swagger文档默认访问路由地址
/// </summary> /// </summary>

View File

@@ -1571,6 +1571,41 @@
请求验证错误处理 请求验证错误处理
</summary> </summary>
</member> </member>
<member name="T:CoreCms.Net.Web.WebApi.Infrastructure.SucceededStateExpireHandler">
<summary>
已完成的job设置过期防止数据无限增长
</summary>
</member>
<member name="F:CoreCms.Net.Web.WebApi.Infrastructure.SucceededStateExpireHandler.JobExpirationTimeout">
<summary>
数据过期时间
</summary>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Infrastructure.SucceededStateExpireHandler.#ctor(System.Int32)">
<summary>
完成的项目过期状态处理
</summary>
<param name="jobExpirationTimeout"></param>
</member>
<member name="P:CoreCms.Net.Web.WebApi.Infrastructure.SucceededStateExpireHandler.StateName">
<summary>
状态名称
</summary>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Infrastructure.SucceededStateExpireHandler.Apply(Hangfire.States.ApplyStateContext,Hangfire.Storage.IWriteOnlyTransaction)">
<summary>
应用状态
</summary>
<param name="context"></param>
<param name="transaction"></param>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Infrastructure.SucceededStateExpireHandler.Unapply(Hangfire.States.ApplyStateContext,Hangfire.Storage.IWriteOnlyTransaction)">
<summary>
不应用状态
</summary>
<param name="context"></param>
<param name="transaction"></param>
</member>
<member name="T:CoreCms.Net.Web.Controllers.WeChat.WeChatOffiaccountNotifyController"> <member name="T:CoreCms.Net.Web.Controllers.WeChat.WeChatOffiaccountNotifyController">
<summary> <summary>
微信公众号消息推送对接 微信公众号消息推送对接

View File

@@ -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)
{
}
}
}

View File

@@ -244,6 +244,10 @@ var hangfireOptions = new Hangfire.DashboardOptions
app.UseHangfireDashboard("/job", hangfireOptions); //可以改变Dashboard的url app.UseHangfireDashboard("/job", hangfireOptions); //可以改变Dashboard的url
HangfireDispose.HangfireService(); HangfireDispose.HangfireService();
//设置hangfire定时任务过期时间
GlobalStateHandlers.Handlers.Add(new SucceededStateExpireHandler(AppSettingsConstVars.HangFireJobExpirationTimeOut));
#endregion #endregion

View File

@@ -10,8 +10,9 @@
}, },
//定时任务管理面板的账户密码 //定时任务管理面板的账户密码
"HangFire": { "HangFire": {
"Login": "CoreShopProfessional", "Login": "CoreShopProfessional", //登录账号
"PassWord": "uzmp0oq9wfbdeasygj647vr53" "PassWord": "uzmp0o3213217vr53", //登录密码
"JobExpirationTimeOut": "10080" //已经完成的任务过期时间单位分钟默认10080,7天时间
}, },
//Swagger授权访问设置 //Swagger授权访问设置
"SwaggerConfig": { "SwaggerConfig": {