Ok, thanks for the code. Target queue can be changed during the state election process, that can be extended by user-defined classes, called filters. You can look at QueueAttribute for example, it is just an extension. You can solve your problems by creating the following filter:
public class UseIndexPopulationQueueAttribute : JobFilterAttribute, IElectStateFilter
{
public void OnStateElection(ElectStateContext context)
{
var enqueuedState = context.CandidateState as EnqueuedState;
if (enqueuedState != null)
{
enqueuedState.Queue = Config.HangfireQueuePrefix + "index_population_bg";
}
}
}
And then apply it to your method:
[UseIndexPopulationQueue]
public void PopulateIndexBG() { }
You can also look at properties available in context argument, and use them to determine the queue name:
if (context.Job.Method.Name.StartsWith("PopulateIndex"))
{
enqueuedState.Queue = "st_index_population_bg";
}
And add a filter globally for all your jobs, so you don’t even need to apply it to your methods as queue name will be determined automatically.