Reputation: 162
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.
Upvotes: 2
Views: 14720
Reputation: 162
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();
}
Upvotes: 5
Reputation: 770
The CommandTimeout
property on SqlServerStorageOptions
should be what you are looking for.
Increase this to be more than 30 minutes and your jobs will stop timing out.
Upvotes: 4