I'm using Hangfire on a NET 7 ASP.net application (Hangfire version 1.7.34). My issue is that after 30 minutes the job is killed (this job syncs availabilities from an external solution and it can take more than 30 minutes, sometimes even double).
I've just googled and found here information that starting from version 1.5 the InvisibilityTimeout is deprecated.
I've seen that with other providers it can still be done, but in my case, I've to run it from SQLServerStorage.
Here's my existing code:
public static void ConfigureHangfireServices(this IServiceCollection services, IConfiguration configuration)
{
var appSettingsSection = configuration.GetSection("Settings");
var appSettings = appSettingsSection.Get<AppSettings>();
if (appSettings.EnableHangfireServices)
{
services.AddSingleton<IBackgroundJobManager, HangfireBackgroundJobManager>();
services.AddHangfire(options =>
{
options.SetDataCompatibilityLevel(CompatibilityLevel.Version_170);
options.UseSerilogLogProvider();
options.UseSimpleAssemblyNameTypeSerializer();
options.UseRecommendedSerializerSettings();
var connectionString = configuration.GetConnectionString("HangfireConnection");
if (string.IsNullOrEmpty(connectionString))
{
options.UseMemoryStorage();
}
else
{
options.UseSqlServerStorage(
configuration.GetConnectionString("HangfireConnection"),
new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
UseRecommendedIsolationLevel = true,
UsePageLocksOnDequeue = true,
DisableGlobalLocks = true,
});
}
});
//add the processing server as IHostedService
services.AddHangfireServer();
services.RegisterJobs();
}
services.AddScoped<IBackgroundJobClient, BackgroundJobClient>(x => new BackgroundJobClient(
new SqlServerStorage(configuration.GetConnectionString("HangfireConnection"))));
}
Any suggestion?