# Task after maximum retires is reaches

**URL:** <https://discuss.hangfire.io/t/task-after-maximum-retires-is-reaches/6468>\
**Category:** question\
**Tags:** recurring\
**Created:** [August 13, 2019, 11:23am UTC](https://discuss.hangfire.io/t/task-after-maximum-retires-is-reaches/6468 "2019-08-13T11:23:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luyolo\_Mgodi](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/luyolo_mgodi/32/1721_2.png) [@Luyolo\_Mgodi](https://discuss.hangfire.io/u/Luyolo_Mgodi)\
**Post date:** [August 13, 2019, 11:23am UTC](https://discuss.hangfire.io/t/task-after-maximum-retires-is-reaches/6468/1 "2019-08-13T11:23:25Z")

</div>

Hey guys,

I was wondering, has anyone implemented anything or precess that get’s triggered when HangFire reached the maximum retries. For example, let’s say hangfire has reached the maximum 10 retries and the job still fails. I’d like to send an email to myself about it.

---

<div class="post-metadata">

**Author:** ![alien](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@alien](https://discuss.hangfire.io/u/alien)\
**Post date:** [August 13, 2019, 11:39am UTC](https://discuss.hangfire.io/t/task-after-maximum-retires-is-reaches/6468/2 "2019-08-13T11:39:23Z")

</div>

I have implemented this by creating a custom job filter which does the following:

```auto
 public void OnStateElection(ElectStateContext context)
        {
            var failedState = context.CandidateState as FailedState;
            if (failedState != null)
            {
                var retryAttempt = context.GetJobParameter<int>("RetryCount") + 1;
                var maxAttempts = _schedulerConfiguration.MaxNumberOfRetries;
                if (retryAttempt == maxAttempts) {
                     // Send an email
                }
            }
        }

```

---

<div class="post-metadata">

**Author:** ![Luyolo\_Mgodi](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/luyolo_mgodi/32/1721_2.png) [@Luyolo\_Mgodi](https://discuss.hangfire.io/u/Luyolo_Mgodi)\
**Post date:** [August 13, 2019, 12:30pm UTC](https://discuss.hangfire.io/t/task-after-maximum-retires-is-reaches/6468/3 "2019-08-13T12:30:44Z")

</div>

Thanks for this.

I’m using a webapi, do I put this on the startup where I do the Hangfire configuration ?
