EDIT: After pulling in the Hangfire source and some tentative debugging, I realised my Filter wasn’t applied in the context of one of my BackgroundJobProcessors. Whoops! That was enough to fix my issue.
I have a Job scheduled with BackgroundJobClient:
var client = new BackgroundJobClient();
client.Create<MyBackgroundJob>(j => j.RunMyJob(jobKey), new ScheduledState(TimeSpan.FromSeconds(10)));
I also have a custom JobFilterAttribute
with the IElectStateFilter
interface.
When the Job is initially Scheduled, OnStateElection is successfully called.
When the Job moves to from Scheduled to Enqueued, OnStateElection is not called.
I have also implemented IApplyStateFilter
and neither of its methods appear to be called when moving from Scheduled to Enqueued either.
Is this expected behaviour?
Is there another Interface I should be implementing to recieve these events?
Ideally, I would like to use the jobKey
argument of my Job to dynamically place it on a specific queue - this works well when my Jobs fail and requeue but not for this scenario which makes me think there may be a legitimate bug here?