Skip to content

Background job is ignoring Queue attribute if i am using BackgroundJob.Enqueue() #2498

Open
@benzmarkus

Description

@benzmarkus

Description
I used a background job and added a queue attribute. I wrote a custom jobfilter attribute
public class DisableMultipleQueuedItemsAttribute : JobFilterAttribute, IClientFilter, IServerFilter, IElectStateFilter {}
to calculate a fingerprint to ensure a backgroundjob is not called multiple times.

In the Attribute I can read the job parameter and queue is null there.

Steps to Reproduce

------------------------- hangfire config start----------------------
var jobStorage = new SqlServerStorage(_configuration.GetConnectionString("MyConnectionString"));

// Add Hangfire services
services.AddHangfire(configuration =>
{
configuration.UseStorage(jobStorage);
});

services.AddHangfireServer((_, backgroundJobServerOptions) =>
{
backgroundJobServerOptions.Queues = new[] { "WinService", "default") };
backgroundJobServerOptions.WorkerCount = 5;
});
------------------------- hangfire config end----------------------

------------------------- Backgroundjob start----------------------
[Queue("WinService")]
[DisableMultipleQueuedItems]
public async Task SynchronizeAsync(int param1, int param2) {}
------------------------- Backgroundjob end----------------------

------------- calling the job --------------------
BackgroundJob.Enqueue(x => x.SynchronizeAsync(param1, param2);

Observed Behavior
when I set the debugger in my custom attribute the jobs queue is null

Expected Behavior
Queue is set to "WinService" but is null. The correct hangfire process is executing the job

------------------------- hangfire config start----------------------
var jobStorage = new SqlServerStorage(_configuration.GetConnectionString("MyConnectionString"));

// Add Hangfire services
services.AddHangfire(configuration =>
{
configuration.UseStorage(jobStorage);
});

services.AddHangfireServer((_, backgroundJobServerOptions) =>
{
backgroundJobServerOptions.Queues = new[] { "webui") };
backgroundJobServerOptions.WorkerCount = 5;
});
------------------------- hangfire config end----------------------

Additional Information
My setup was:

.NET 6
Hangfire 1.8.17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions