如何在Hangfire(Postgresql)中设置成功作业的自动删除



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

请参阅链接: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)
{
}
}

最新更新