【问题标题】:How to setup auto delete of successful jobs in Hangfire (Postgresql)如何在 Hangfire (Postgresql) 中设置成功作业的自动删除
【发布时间】:2020-04-13 15:29:56
【问题描述】:

我有几个作业计划在 PostgreSql 支持的 Hangfire 中每 5 分钟运行一次。我看到当使用 SQL 服务器时,成功的作业会自动从数据库中删除。我在 PostGreStorageOptions 中找不到类似的东西。知道如何在 postgresql 中设置自动删除成功的作业吗?

【问题讨论】:

    标签: postgresql .net-core hangfire hangfire-sql


    【解决方案1】:

    见链接:https://discuss.hangfire.io/t/how-to-configure-the-retention-time-of-job/34 我写了一个自定义类,例如:

    public class AutoDeleteAfterSuccessAttribute : JobFilterAttribute, IApplyStateFilter
    {
        private readonly TimeSpan _deleteAfter;
    
        public AutoDeleteAfterSuccessAttribute(int hours, int minutes, int seconds)
        {
            _deleteAfter = new TimeSpan(hours, minutes, seconds);
        }
    
        public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
        {
            context.JobExpirationTimeout = _deleteAfter;
        }
    
        public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
        {
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 2017-03-09
      • 1970-01-01
      • 2018-07-23
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      相关资源
      最近更新 更多