Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase hangfire job timeout

I have a .net core application which has hangfire 1.7.2 running.

So I have this job, which executes SQL stored procedure and its a long running task, can be of 30 minutes.

This gives me following error: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated.

services.AddHangfire(configuration => 

configuration.UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection"), 
new SqlServerStorageOptions
    {
        SlidingInvisibilityTimeout = TimeSpan.FromMinutes(30),
        QueuePollInterval = TimeSpan.Zero,
        UsePageLocksOnDequeue = false,
        DisableGlobalLocks = false
    }));

Please help me out.

like image 342
Gaurav Avatar asked Oct 30 '25 16:10

Gaurav


1 Answers

I managed to fix this by increasing SQLCommand timeout which is by default 30 seconds.

 using (SqlCommand cmd = new SqlCommand(query, con))
 {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandTimeout = 3600; // 1 hour
        await cmd.ExecuteNonQueryAsync();
 }
like image 134
Gaurav Avatar answered Nov 01 '25 07:11

Gaurav