The queue name of the job triggered by requeue button in the dashboard is always default
Hi guys,
I found the queue name of the job tiggered by requeue button in the dashboard is always default.


Because after receiving the requeue request, it always uses the default no-argument constructor to create a new EnqueuedState
https://github.com/HangfireIO/Hangfire/blob/88504456704b6fa590a25a694f1e877b922a9da1/src/Hangfire.Core/Dashboard/DashboardRoutes.cs#L122-L125
https://github.com/HangfireIO/Hangfire/blob/88504456704b6fa590a25a694f1e877b922a9da1/src/Hangfire.Core/Dashboard/DashboardRoutes.cs#L192-L196
https://github.com/HangfireIO/Hangfire/blob/88504456704b6fa590a25a694f1e877b922a9da1/src/Hangfire.Core/States/EnqueuedState.cs#L89-L92
So I had to create an attribute and apply it to each method of jobs to solve this issue?
internal class RequeueJobIssueFixAttribute : JobFilterAttribute, IApplyStateFilter
{
public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
{
var status = context.NewState as EnqueuedState;
if (status == null)
{
return;
}
if (status.Queue != EnqueuedState.DefaultQueue)
{
return;
}
var jobDetails = context.Storage.GetMonitoringApi().JobDetails(context.BackgroundJob.Id);
var queueName = jobDetails.History.FirstOrDefault(d => d.StateName == EnqueuedState.StateName)?.Data["Queue"];
if (!string.IsNullOrEmpty(queueName))
{
status.Queue = queueName;
}
}
public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
{
return;
}
}
Hope this helps, Will you guys fix it at next release? So we needn't to use this attribute in every method.
Thanks
You can register that attribute globally using GlobalJobFilters. It will be applied to all the jobs automatically. See this article for more details: https://earwicker.com/Hangfire_A_Tale_of_Several_Queues.html
I'm not sure if that behavior is going to be changed in future releases.
Hi Frazi1, thanks for your response and the article is helpful, then requeue to default queue is this a bug or is it designed in this way?
I believe there is a conversation with @odinserj somewhere either in GitHub issues or in https://discuss.hangfire.io/ where he confirmed it to be the expected behavior.
Also, checkout https://github.com/HangfireIO/Hangfire/releases/tag/v1.8.0-beta3 release. It mentions the following change:
Added – Introduce the Job.Queue property, so jobs now can have their own queue specified.
With that new feature, Hangfire's behavior may be changed. But I haven't tested it myself.
got it, thank you.
I get the same problem now. the code here, create a new State instance instead of the original State when reschedule job. Is there any reason to discard the original State ?