I'm using Hangfire 1.5.3 and .NET 4.5.2
If I have the following project:
// TestJob.cs
using Hangfire;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace HangfireRecuringQueueTest
{
public class TestJob
{
[Queue("MY_QUEUE")]
[DisableConcurrentExecution(5 * 60)]
public void Execute()
{
Console.WriteLine(1 + 1);
}
}
}
// Startup.cs
using Hangfire;
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(HangfireRecuringQueueTest.Startup))]
namespace HangfireRecuringQueueTest
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration.UseSqlServerStorage("Hangfire");
app.UseHangfireDashboard();
app.UseHangfireServer(new BackgroundJobServerOptions
{
Queues = new[] { "MY_QUEUE", "default" }
});
RecurringJob.AddOrUpdate<TestJob>("my-recuring-job", (j) => j.Execute(), Cron.Minutely);
}
}
}
<!-- Web.config -->
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<connectionStrings>
<add name="Hangfire" providerName="System.Data.SqlClient" connectionString="Server=(localdb)\v11.0; Database=Hangfire; trusted_connection=true; pooling=false" />
</connectionStrings>
</configuration>
Hangfire never en-queues the job that is setup in the startup class. Furthermore, jobs cannot be forcefully en-queued:

It looks like the Jobs are being created in the database:

If I remove the [Queue("MY_QUEUE")] Attribute, the task processes as expected:

Specifying the queue parameter doesn't seem to work either:
RecurringJob.AddOrUpdate<TestJob>("my-recuring-job", (j) => j.Execute(), Cron.Minutely, queue: "MY_QUEUE");
Hangfires queue names have some rules.
A queue name may only contain lowercase characters, numbers or underscores and has a maximum length of 20 characters.
Whilst I haven't run into this, it'd be good if Hangfire wrote something out to the log at an error level when this was discovered. You'd only want it once per bad queue name I suppose.
Note: it may well do this already, but if it doesn't, it'd be worth adding to save some head scratching.
Most helpful comment
Whilst I haven't run into this, it'd be good if Hangfire wrote something out to the log at an error level when this was discovered. You'd only want it once per bad queue name I suppose.
Note: it may well do this already, but if it doesn't, it'd be worth adding to save some head scratching.