Deleting not succeeded jobs in Hangfire on startup

Viewed 137

While using Hangfire, when the worker is stopped in which hangfire is used, the jobs get stuck with status "Processing" or "Scheduled". And on next startup the jobs get automatically executed. I am having trouble deleting the old jobs from the previous instance of my worker. I tried executing this when the worker is being started, but the jobs execute before this.

    var jobsToDelete = await _hangfireJobRepository.RetrieveAllNotSucceededJobs();

    foreach (var job in jobsToDelete)
    {
        BackgroundJob.Delete(job.Id.ToString());
    }

Is there any way i can solve this?

0 Answers
Related