Recurring Job Deleted Event

I have a recurring job that connects to a ftp server. I understand it is not best practice to pass sensitive information like ftp credentials as job parameters and instead should store credentials in application database and pass the record identity as job parameter.

Problem is if I store credentials outside of Hangfire and the user deletes the recurring job using the dashboard as far as I can tell I would have no way of knowing that the ftp credential record should be removed and am storing credentials un-necessarily.

Is there some kind of extension or dashboard option that can be subscribed to notify application that a recurring job has been removed from the dashboard?

I was looking for same thing and solved it by registering custom middleware that intercepts the recurring job remove request and does the action that I needed to invoke. Here is sample middleware:

public class HangfireRemoveRecurringJob {
    private readonly RequestDelegate next;

    public HangfireRemoveRecurringJob(RequestDelegate next) {
        this.next = next;
    }

    public async Task InvokeAsync(HttpContext httpContext) {
        if (httpContext.Request.Path.StartsWithSegments("/hangfire/recurring/remove")) {
            var form = await httpContext.Request.ReadFormAsync();
            var jobIds = form["jobs[]"];

            foreach (var jobId in jobIds)
                //invoke your custom remove logic here
        }

        await this.next(httpContext);
    }
}

And you just have to register it with IApplicationBuilder:

 app.UseMiddleware<HangfireRemoveRecurringJob>();