简体   繁体   English

如何增加hangfire作业超时

[英]How to increase hangfire job timeout

I have a .net core application which has hangfire 1.7.2 running.我有一个运行 hangfire 1.7.2 的 .net 核心应用程序。

So I have this job, which executes SQL stored procedure and its a long running task, can be of 30 minutes.所以我有这个工作,它执行 SQL 存储过程及其长时间运行的任务,可能需要 30 分钟。

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.请帮帮我。

The CommandTimeout property on SqlServerStorageOptions should be what you are looking for. SqlServerStorageOptions上的CommandTimeout属性应该是您正在寻找的。

Increase this to be more than 30 minutes and your jobs will stop timing out.将此时间增加到 30 分钟以上,您的作业将停止超时。

(See source https://github.com/HangfireIO/Hangfire/blob/cf7bb08d24ee4953926b7717461bf8a23d895eb4/src/Hangfire.SqlServer/SqlServerConnection.cs ) (见源码https://github.com/HangfireIO/Hangfire/blob/cf7bb08d24ee4953926b7717461bf8a23d895eb4/src/Hangfire.SqlServer/SqlServerConnection.cs

I managed to fix this by increasing SQLCommand timeout which is by default 30 seconds.我设法通过增加默认为 30 秒的SQLCommand超时来解决此问题。

 using (SqlCommand cmd = new SqlCommand(query, con))
 {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandTimeout = 3600; // 1 hour
        await cmd.ExecuteNonQueryAsync();
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM