Failed to set the expiration attribute of Hangfire.

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)
    {
        // ... other stuff here ...
        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,

enter image description here

?

+4
1

, . , startup.cs asp.net web api, .

Console, ,

static void Main(string[] args)
{
    GlobalConfiguration.Configuration.UseSqlServerStorage("HangFireDBConnection");
    GlobalJobFilters.Filters.Add(new OneYearExpirationTimeAttribute());
    // ... more stuff ...
}

. Hangfire , .

+1

Source: https://habr.com/ru/post/1670926/


All Articles