How to properly use JobFilterAttribute?


I’m trying to add a fallback functionality to some jobs, so that when it ends in Failed state, some custom code will be executed.
The way to do it - as I understood it from various posts and samples - is to use a custom job filter. Unfortunately, it seemed to be completely ignored.
To check out why, I’ve tried to use the built-in AutomaticRetry attribute first:

[AutomaticRetry(Attempts = 2, Order = 1)]
public void RunMyCustomCode(string parameter1, string parameter2){}

the job is enqueued like this:

public void ScheduleMyCustomCode()
BackgroundJob.Enqueue(service => service.RunMyCustomCode(“abc”, “def”));

When RunMyCustomCode throws, I see:

Failed to process the job '564': an exception occurred. Retry attempt 1 of 10 will be performed in 00:00:18.|MyApp.MyException: Exception content
   at MyService.RunMyCustomCode(String parameter1, String parameter2) in c:\...\...cs:line 123 

It seems that the attribute gets ignored. That would explain why my custom ones didn’t work as well. What am I doing wrong?

I’m using Hangfire 1.4.6

I resolved it myself - also, the problem description is missing key information: the service is resolved as an interface. And apparently the JobFitlers are not inherited. Putting the attribute on ITNERFACE method, instead of CLASS helped.