I use Hangfire to complete tasks, and I would like to change the behavior that deleted tasks are deleted from the database every other day — I would like them to be stored for a year.
Following the instructions in this thread , which matches this SO question , I created a class:
public class OneYearExpirationTimeAttribute : JobFilterAttribute, IApplyStateFilter
{
public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
{
context.JobExpirationTimeout = TimeSpan.FromDays(365);
}
public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
{
context.JobExpirationTimeout = TimeSpan.FromDays(365);
}
}
and I will register it in my api app.net startup class as a global filter:
public class Startup
{
public void Configuration(IAppBuilder app)
{
GlobalJobFilters.Filters.Add(new OneYearExpirationTimeAttribute());
GlobalConfiguration.Configuration.UseSqlServerStorage("HangFireDBConnection");
app.UseHangfireDashboard();
}
}
Web api is the place where vacancies are placed (i.e. a call is made BackgroundJob.Enqueue(() => ...)). I have not changed the configuration of clients who perform actual tasks.
, , , , HangfireDb,

?