簡體   English   中英

如何在 Hangfire (Postgresql) 中設置成功作業的自動刪除

[英]How to setup auto delete of successful jobs in Hangfire (Postgresql)

我有幾個作業計划在由 PostgreSql 支持的 Hangfire 中每 5 分鍾運行一次。 我看到當使用 SQL 服務器時,成功的作業會自動從數據庫中刪除。 我在 PostGreStorageOptions 中找不到類似的東西。 知道如何在 postgresql 中設置成功作業的自動刪除嗎?

見鏈接: https://discuss.hangfire.io/t/how-to-configure-the-retention-time-of-job/34我寫了一個自定義的 class 如:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM