# Filter to handle failed jobs

**URL:** <https://discuss.hangfire.io/t/filter-to-handle-failed-jobs/5251>\
**Category:** question\
**Tags:** job-filters\
**Created:** [September 18, 2018, 1:58pm UTC](https://discuss.hangfire.io/t/filter-to-handle-failed-jobs/5251 "2018-09-18T13:58:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![HolyChicken](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@HolyChicken](https://discuss.hangfire.io/u/HolyChicken)\
**Post date:** [September 18, 2018, 1:58pm UTC](https://discuss.hangfire.io/t/filter-to-handle-failed-jobs/5251/1 "2018-09-18T13:58:34Z")

</div>

Hey All,

I have created a filter  
`JobFailureFilter`

It is supposed to check if a job goes to failed state, and notify the client after having retried 10 times.

I have registered the filter like this:  
`GlobalJobFilters.Filters.Add(new JobFailureFilter(serviceProvider.GetService<IJobManager>(), serviceProvider.GetService<IStatusReportingClient>()));`

The filter implements all of the interfaces:  
`JobFilterAttribute,IClientFilter, IServerFilter, IElectStateFilter, IApplyStateFilter`

But my problem is that after the 10’th attempt, it does not enter  
`public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)`

it does enter OnStateApplied when i requeue the job from the dashboard, with the Enqueued state, but when the job throws an exception, it does not change the state to failed, but the job is in failed state in the dashboard.

I have also tried to do it in `OnStateElection` but it does not enter any of the interface methods after the job throws an exception
