I am showing list of hangfire servers currently running on my page.
I am running hangfire server in console application but the problem is when I don't have my console application running still hangfire api returns hangfire servers.
Moreover when I run my console application multiple times I get 3-4 hangfire servers though I have only 1 hangfire server running in console application.
Mvc application :
IMonitoringApi monitoringApi = JobStorage.Current.GetMonitoringApi();
var servers = monitoringApi.Servers().OrderByDescending(s => s.StartedAt);
Console Application:Hangfire server
public static void Main(string[] args)
{
var sqlServerPolling = new SqlServerStorageOptions
{
QueuePollInterval = TimeSpan.FromSeconds(20) // Default value
};
GlobalConfiguration.Configuration.UseSqlServerStorage("ConnectionString", sqlServerPolling);
// Set automatic retry attempt
GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 });
// Set worker count
var options = new BackgroundJobServerOptions
{
WorkerCount = 1,
};
using (var server = new BackgroundJobServer(options))
{
Console.WriteLine("Hangfire Server1 started. Press any key to exit...");
Console.ReadKey();
}
}
Hangfire server doenst automatically remove old server data whenever I run my console application again for that particular server?
I will appreciate any help :)
I dug through the source code to find:
If you want to see the code yourself, here are the related source code files:
Mapping of db server.Id
Background server announcement
Delete server from db with id
Code to generate server id
Via the last link, it's also clear that you can customize your server name to make it easier to find and remove: