Queue attribute with wildcard

I have the following code:

 var options1 = new BackgroundJobServerOptions()
{
    ServerName = "server1",
    Queues = new[] { "Q01S01" }
};

cfg.UseServer(options1);

var options2 = new BackgroundJobServerOptions()
{
    ServerName = "server2",
    Queues = new[] { "Q01S02" }
};

cfg.UseServer(options2);

Job implementation:

public class TestJob1
{
    [Queue("Q01*")] // queue attribute with wildcard format
    public void Execute(string param)
    {
        //do something
    }
}

Is Hangfire support for creating attribute with wildcard, so in this example with [Queue("Q01*")] we can run this job in Server1 and Server2

hi @odinserj,

Could you help me on this question? Thanks

I have a similar situation where I need to have queues for each server. Because the work they do is tied to the files stored on each one. So each of each of my servers consume two queues, “servername” and “default”. For tasks that aren’t server-specific, any server will pick up default.

var options1 = new BackgroundJobServerOptions()
{
    ServerName = "server1",
    Queues = new[] { "Q01S01", "default" }
};

cfg.UseServer(options1);

var options2 = new BackgroundJobServerOptions()
{
    ServerName = "server2",
    Queues = new[] { "Q01S02", "default" }
};

cfg.UseServer(options2);


//    [Queue("default")] 
public void Execute(string param)
{
    //do something
}
1 Like