# How can we modify the batches expiration time?

**URL:** <https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400>\
**Category:** question\
**Tags:** redis, hangfire-pro\
**Created:** [September 7, 2016, 1:08pm UTC](https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400 "2016-09-07T13:08:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Massimo\_Zerbini](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@Massimo\_Zerbini](https://discuss.hangfire.io/u/Massimo_Zerbini)\
**Post date:** [September 7, 2016, 1:08pm UTC](https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400/1 "2016-09-07T13:08:31Z")

</div>

I’m using Hangfire Pro and Redis as storage backend. I see the new release 1.4.6 blog post and it’s great.  
But there is a point that it’s not clear for me: How can I modify the batches expiration time?  
Can I use a filter like this [How to configure the retention time of job?](http://hangfire.discourse.group/t/how-to-configure-the-retention-time-of-job/34) ?

Thanks & Regards,  
Massimo

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [September 8, 2016, 3:16pm UTC](https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400/2 "2016-09-08T15:16:44Z")

</div>

Currently there are two ways, but both of them are hacky:

1. Change a value of the internal field `Hangfire.Batches.States.ApplyBatchStateContext.DefaultBatchExpirationTime` (`TimeSpan`) using reflection.
2. Download the source code, change the value and switch the assemblies.

I’m planning to make batch filters public in the next Hangfire.Pro 1.5.0 version. They will behave like job filters, and you’ll be able to change some aspects of batch processing, including their expiration time. I will touch this topic once there is a build with this feature in the Private CI NuGet feed.

---

<div class="post-metadata">

**Author:** ![sumeetg](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@sumeetg](https://discuss.hangfire.io/u/sumeetg)\
**Post date:** [February 2, 2017, 5:03pm UTC](https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400/3 "2017-02-02T17:03:12Z")

</div>

Hi @odinserj,

Are you able to show an example with the latest Hangfire Pro to use filters with batching? No matter what I do it does not honor the expiration filter. The same code works fine without batching.

Thanks

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [February 2, 2017, 5:26pm UTC](https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400/4 "2017-02-02T17:26:34Z")

</div>

Hi @sumeetg, currently you can use the following method to configure expiration time for batch and its jobs:

```auto
private static bool SetBatchExpirationTime(TimeSpan expirationTime)
{
    var type = Type.GetType("Hangfire.Batches.States.ApplyBatchStateContext, Hangfire.Pro", throwOnError: false);
    if (type == null) return false;

    var field = type.GetField("DefaultBatchExpirationTime", BindingFlags.Static | BindingFlags.NonPublic);
    if (field == null) return false;

    field.SetValue(null, expirationTime);
    return true;
}

```

---

<div class="post-metadata">

**Author:** ![sumeetg](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@sumeetg](https://discuss.hangfire.io/u/sumeetg)\
**Post date:** [February 2, 2017, 5:30pm UTC](https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400/5 "2017-02-02T17:30:46Z")

</div>

Thx, is there any plan to change this to use the filtering? I love the filtering since I can control it on every job with just a simple attribute. We are using the latest of Core and Pro.

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [February 2, 2017, 5:38pm UTC](https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400/6 "2017-02-02T17:38:04Z")

</div>

Even if I make filters for batches available for everyone, it will be hard to differentiate one batch from another. The only option available is to use their descriptions, but it will be very strange. Currently I consider to have a global setting for batches, like `IGlobalConfiguration.UseBatches(TimeSpan expirationTime)`.

---

<div class="post-metadata">

**Author:** ![sumeetg](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@sumeetg](https://discuss.hangfire.io/u/sumeetg)\
**Post date:** [February 2, 2017, 5:56pm UTC](https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400/7 "2017-02-02T17:56:40Z")

</div>

Ok got it. Just tested with the code you provided and it does indeed work. Also wanted to say great work on this product, really loving the batching.

---

<div class="post-metadata">

**Author:** ![Mark\_Evans](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/mark_evans/32/676_2.png) [@Mark\_Evans](https://discuss.hangfire.io/u/Mark_Evans)\
**Post date:** [April 11, 2018, 6:24pm UTC](https://discuss.hangfire.io/t/how-can-we-modify-the-batches-expiration-time/2400/8 "2018-04-11T18:24:29Z")

</div>

How and where do i do this? Can you document this?
