# Possible problem with Queues an Batches

**URL:** <https://discuss.hangfire.io/t/possible-problem-with-queues-an-batches/11428>\
**Category:** bug?\
**Tags:** queues\
**Created:** [May 19, 2026, 10:34am UTC](https://discuss.hangfire.io/t/possible-problem-with-queues-an-batches/11428 "2026-05-19T10:34:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MauSamba](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/mausamba/32/3330_2.png) [@MauSamba](https://discuss.hangfire.io/u/MauSamba)\
**Post date:** [May 19, 2026, 10:34am UTC](https://discuss.hangfire.io/t/possible-problem-with-queues-an-batches/11428/1 "2026-05-19T10:34:02Z")

</div>

Hi,

we use hangfire with batches and Queues and we faced an “issue”.

We have jobs like this  
[Hangfire.Queue(“a-altapriorita”)]  
public async Task TestJob(string method)  
{  
[…]  
return;  
}

differents enqueing method seems to not always use queues  
BackgroundJob.Enqueue(x =\> x.TestJob(“BackgroundJob”));  
var batchid = BatchJob.StartNew(x =\>{x.Enqueue(x =\> x.TestJob(“StartNew”));});  
BatchJob.Attach(batchid, x =\>{x.Enqueue(x =\> x.TestJob(“Attach”));});

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/hangfire/original/2X/6/6a7c82ef2a23e55ea2a4b4e415e2ae2d97a29682.png)

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/hangfire/original/2X/5/5cef0656c1e02a04db4b598c49d1adda84bc263a.png)(same for “StartNew”)

Are we missing some configuration?

Really appreciate your work!

---

<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:** [May 20, 2026, 10:24am UTC](https://discuss.hangfire.io/t/possible-problem-with-queues-an-batches/11428/2 "2026-05-20T10:24:42Z")

</div>

Hi, I don’t see the issue, and the `Attach` job goes to the correct queue.

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/hangfire/original/2X/b/b5dd88b2367ee22004c5479148be2237318b5345.png)

What Hangfire.Pro version you are using, and is it possible that the `Attach` method was processed by an older version of the code base without the `Queue` attribute specified?

---

<div class="post-metadata">

**Author:** ![MauSamba](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/mausamba/32/3330_2.png) [@MauSamba](https://discuss.hangfire.io/u/MauSamba)\
**Post date:** [May 21, 2026, 7:12am UTC](https://discuss.hangfire.io/t/possible-problem-with-queues-an-batches/11428/3 "2026-05-21T07:12:25Z")

</div>

we are using redis with this configuration

> ```auto
> <TargetFramework>net10.0</TargetFramework>
> 
> <PackageReference Include="Hangfire.AspNetCore" Version="1.8.23" />
> <PackageReference Include="Hangfire.Pro.Redis" Version="3.3.1" />
> <PackageReference Include="Hangfire.Throttling" Version="1.4.3" />
> 
> ```

> ```auto
> builder.Services.AddHangfire(c => c
> .SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
> .UseSimpleAssemblyNameTypeSerializer()
> .UseRecommendedSerializerSettings()
> .UseThrottling()
> .UseRedisStorage("XXXXXXXX",
> new Hangfire.Pro.Redis.RedisStorageOptions
> {
> Database = XXXXXX,
> })
> .UseBatches(TimeSpan.FromDays(1), new ExpirationTimeFilterProvider())
> .UseFilter(new ExpirationTimeAttribute()));
> 
> builder.Services.AddHangfireServer(options =>
> {
> options.WorkerCount = Environment.ProcessorCount * XXXXX;
> options.Queues = new[]
> {
> "a-altapriorita",
> "b-mediapriorita",
> "c-bassapriorita",
> "z-default"
> "default"
> };
> });
> 
> ```

The methods are enqueued and processed by the same application

---

<div class="post-metadata">

**Author:** ![MauSamba](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/mausamba/32/3330_2.png) [@MauSamba](https://discuss.hangfire.io/u/MauSamba)\
**Post date:** [May 27, 2026, 3:54pm UTC](https://discuss.hangfire.io/t/possible-problem-with-queues-an-batches/11428/4 "2026-05-27T15:54:02Z")

</div>

we found that this filter was the problem

> .UseBatches(TimeSpan.FromDays(1), new ExpirationTimeFilterProvider())

> public class ExpirationTimeAttribute : JobFilterAttribute, IApplyStateFilter  
> {  
> public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)  
> {  
> if (context.NewState is SucceededState)  
> context.JobExpirationTimeout = TimeSpan.FromHours(8);
> 
> ```
> }
> 
> public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
> {
>     
> }
> 
> ```
> 
> }
> 
> public class ExpirationTimeFilterProvider : IJobFilterProvider  
> {  
> public ExpirationTimeFilterProvider()  
> {  
> }
> 
> ```
> public IEnumerable<JobFilter> GetFilters(Job job)
> {
> yield return new JobFilter(new ExpirationTimeAttribute(), JobFilterScope.Global, null);
> }
> 
> ```
> 
> }

It was created to optimize jobs expiration because we noticed that batch jobs clogs our redis server.

I’ve updated it like this

> public IEnumerable GetFilters(Job job)  
> {  
> foreach (var filter in JobFilterProviders.Providers.GetFilters(job))  
> {  
> yield return filter;  
> }
> 
> ```auto
> yield return new JobFilter(new ExpirationTimeAttribute(), JobFilterScope.Global, null);
> 
> ```
> 
> }

Now the queues works again

Still we don’t understand why in production some jobs enqueued by batches were still using queues and some doesn’t

 ![queue](https://europe1.discourse-cdn.com/flex017/uploads/hangfire/original/2X/3/354880e738e18c8cbf09fcc94a8e665806cfb006.png)enqueue with “start new”

 ![no queue](https://europe1.discourse-cdn.com/flex017/uploads/hangfire/original/2X/a/ad9bc000651cad97a57b508663fd417130c5aef0.png)enqueued with “attach”

both have the correct attribute

---

<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:** [May 29, 2026, 5:24pm UTC](https://discuss.hangfire.io/t/possible-problem-with-queues-an-batches/11428/5 "2026-05-29T17:24:31Z")

</div>

I think that the following line:

```csharp
.UseBatches(TimeSpan.FromDays(1), new ExpirationTimeFilterProvider())

```

should be changed to:

```csharp
.UseBatches(TimeSpan.FromDays(1))

```

The `ExpirationTimeAttribute` filter is already registered with the `UseFilter` method, and batches know about the main filter provider that’s modified when calling the `UseFilter`. Filter providers are for other use cases, like backed by some IoC container or modules, and it is a very rare case when you’d need a custom filter provider.

I believe the difference was related by the side which created a background job – if it was created by an application, then the queue attribute was applied correctly, but when a batch was responsible for changing state of a job (such as batch continuation), then QueueAttribute filter was completely ignored, since custom filter provider wasn’t aware of it.
