【发布时间】:2020-04-13 15:29:56
【问题描述】:
我有几个作业计划在 PostgreSql 支持的 Hangfire 中每 5 分钟运行一次。我看到当使用 SQL 服务器时,成功的作业会自动从数据库中删除。我在 PostGreStorageOptions 中找不到类似的东西。知道如何在 postgresql 中设置自动删除成功的作业吗?
【问题讨论】:
标签: postgresql .net-core hangfire hangfire-sql
我有几个作业计划在 PostgreSql 支持的 Hangfire 中每 5 分钟运行一次。我看到当使用 SQL 服务器时,成功的作业会自动从数据库中删除。我在 PostGreStorageOptions 中找不到类似的东西。知道如何在 postgresql 中设置自动删除成功的作业吗?
【问题讨论】:
标签: postgresql .net-core hangfire hangfire-sql
见链接: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)
{
}
}
【讨论】: