Failed jobs never expire/delete
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?
As soon as the retries are depleted the job is removed
As soon as the retries are depleted the job is removed
We have retries set to zero, still not deleted
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.
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.
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.