Keep history of jobs executed for more than 1 day in Hangfire

拟墨画扇 提交于 2019-12-05 14:44:17

To do this, you need to create a job filter and register it through hangfire global configurations, as discussed here - https://discuss.hangfire.io/t/how-to-configure-the-retention-time-of-job/34

Create job filter -

using Hangfire.Common;
using Hangfire.States;
using Hangfire.Storage;
using System;

namespace HangfireDemo
{
    public class ProlongExpirationTimeAttribute : JobFilterAttribute, IApplyStateFilter
    {
        public void OnStateApplied(ApplyStateContext filterContext, IWriteOnlyTransaction transaction)
        {
            filterContext.JobExpirationTimeout = TimeSpan.FromDays(7);
        }

        public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
        {
            context.JobExpirationTimeout = TimeSpan.FromDays(7);
        }
    }
}

...and register in global job filters -

GlobalJobFilters.Filters.Add(new ProlongExpirationTimeAttribute());
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!