Hangfire extension to delete jobs that have been removed from configuration code.
- Delete jobs that have been removed from configuration code.
- Achieve the former objective in a simple/streamlined implementation.
When first configuring a new job on Hangfire, there is a synchronization between the job configuration on code and the job definitions persisted on database.
Then, when removing a job from your code ...
... the corresponding job definition is not removed from the database.
Add a manager that removes jobs no longer defined in code but still persisted in the database, restoring synchronization.
var recurringJobCleanUp = new RecurringJobCleanUpManager(recurringJobManager)
{
EnforceRecurringJob.Create<StoreBookings>("StoreBookings1", bookings => bookings.Execute(),Hangfire.Cron.Minutely()),
EnforceRecurringJob.Create<StoreBookings>("StoreBookings2", bookings => bookings.Execute(),Hangfire.Cron.Minutely())
};
recurringJobCleanUp.AddUpdateDeleteJobs();