Hello,
I’ve been trying to figure out what’s happening with my Hangfire setup for the past week, but to no avail. Basically, I am not able get rid of servers and queues that should not be there. I’m using Hangfire.AspNetCor and Hangfire.SqlServer versions 1.7.25 in an ASP.NET Core 2.2 environment. Here’s what I have in my ConfigureServices:
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(Configuration.GetConnectionString("DB"), new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
UseRecommendedIsolationLevel = true,
DisableGlobalLocks = true
}));
services.AddHangfireServer();
I schedule my background job when a user clicks on a button inside a controller and I give it a timespan of 0 to make the job execute immediately (I’ve also tried Enqueue instead of Schedule):
BackgrounJobs.Schedule(() => runMyCode(), TimeSpan.FromSeconds(0));
In a previous version of my code I had assigned my “runMyCode” routine to a specific queue called “projects” by using the attribute [Queue(“projects”)]. Later I removed this attribute and opted for Hangfire to just use the “default” queue. However, now every time I run my application and view the “servers” in the dashboard I see that there is still a server that has the “projects” queue assigned to it, and no matter what I do when I execute my code it seems to run a older version of my code on that server and in that queue. However, even thought a new server with the default queue is also created, it’s never used.
I have tried truncating all the Hangfire tables in my SQL Server database, I’ve even Dropped all the tables and let Hangfire re-add them. But the “extra” server(s) keep coming back. I’ve even removed the Hangfire package from my dependencies in my application and re-added it, but nothing has changed.
Why is Hangfire running an old version of my code? How can I get rid of the extra server and queues permanently? I have no idea what I’m doing wrong. I’d really appreciate any help. Thanks!