Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

Failed jobs never expire/delete

Open johnwc opened this issue 3 months ago • 5 comments

It seems that failed jobs stick around forever. If we set AutomaticRetry(OnAttemptsExceeded = AttemptsExceededAction.Delete), does that cause them to delete as soon as the job is failed, or after a set amount of time somehow configured?

johnwc avatar Sep 29 '25 18:09 johnwc

As soon as the retries are depleted the job is removed

Toumash avatar Oct 10 '25 13:10 Toumash

As soon as the retries are depleted the job is removed

We have retries set to zero, still not deleted

johnwc avatar Oct 10 '25 19:10 johnwc

It's not a major issue for us but I can confirm as well we have retries set to 0 and I'll periodically go in and delete a few failed jobs that have been in there for a month or two.

cody-watkins avatar Oct 22 '25 19:10 cody-watkins

AttemptsExceededAction.Delete will cause a background job to be moved to the DeletedState, instead of FailedState. DeletedState is similar to SucceededState – they are both considered final ones, and the same expiration rules are applied, 24 hours by default, but 7 days for batched jobs. Expiration time can be configured globally, and it can be specific to a background job, please see https://discuss.hangfire.io/t/how-to-configure-the-retention-time-of-job/34/2.

odinserj avatar Oct 23 '25 09:10 odinserj

Why is a failed state not considered a final one as well? Does hangfire attempt to rerun the job? We need to be able to configure expiration rules for failed state. We don't need failed jobs sticking around forever, which a lot may be duplicate failed states for the same job. We currently have 63k failed jobs that go back about a year. Almost all of them are temporary transient errors from remote services being down for maintenance etc...

Being able to apply a global setting for failed state job expiration, that is different from the other two states, would be nice. And maybe even ability to config a job to delete any previously failed jobs if it succeeds x amount of times.

johnwc avatar Oct 23 '25 19:10 johnwc