Delete failed jobs iwth more than 1 day


#1

How can i delete failed jobs with more than 1 day?

the code i made in VB Net is .
Idx = 0
For Each Job In HangFireMonitor.FailedJobs(0, CInt(HangFireMonitor.FailedCount()))
Idx = Idx + 1

            Console.WriteLine("Idx:" & Idx.ToString & "-Failed Job ID: " & Job.Key)
            ' BackgroundJob.Delete(job.key)
        Next

Now i want to delete all the jobs that failed with more than 1 day.
I have tried to find it but with no sucess.

Thks

doismm


#2

failed with more than 1 day

You mean failed more than one day ago?

Why are you even letting the failed jobs go into the failed bucket at all? You can set failed jobs to be deleted after failing reties.

[Queue("default")]
[AutomaticRetry(Attempts = 5, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
public void BackgroundMethod()
{
    ...
}

See: https://docs.hangfire.io/en/latest/background-processing/dealing-with-exceptions.html