diff --git a/src/Hangfire.SqlServer/SqlServerJobQueue.cs b/src/Hangfire.SqlServer/SqlServerJobQueue.cs index 7b261652b..c6608887f 100644 --- a/src/Hangfire.SqlServer/SqlServerJobQueue.cs +++ b/src/Hangfire.SqlServer/SqlServerJobQueue.cs @@ -90,7 +90,7 @@ private SqlServerTimeoutJob DequeueUsingSlidingInvisibilityTimeout(string[] queu if (queues.Length == 0) throw new ArgumentException("Queue array must be non-empty.", nameof(queues)); var lockResource = $"{_storage.SchemaName}_FetchLockLock_{String.Join("_", queues.OrderBy(x => x))}"; - var isBlocking = false; + var isBlocking = _options.NonBlockingFetchSql; var pollingDelayMs = Math.Min( Math.Max((int)_options.QueuePollInterval.TotalMilliseconds, MinPollingDelayMs), @@ -144,7 +144,7 @@ private SqlServerTimeoutJob DequeueUsingSlidingInvisibilityTimeout(string[] queu throw new InvalidOperationException($"A call to sp_getapplock returned unexpected result '{lockResult.Value}' while fetching a job. Please report this problem to Hangfire developers and don't use sub-second values for the QueuePollInterval option."); } - if (_options.QueuePollInterval < LongPollingThreshold) + if (_options.QueuePollInterval < LongPollingThreshold && !_options.NonBlockingFetchSql) { isBlocking = true; } diff --git a/src/Hangfire.SqlServer/SqlServerStorageOptions.cs b/src/Hangfire.SqlServer/SqlServerStorageOptions.cs index c3229feba..cce5ebf3f 100644 --- a/src/Hangfire.SqlServer/SqlServerStorageOptions.cs +++ b/src/Hangfire.SqlServer/SqlServerStorageOptions.cs @@ -45,6 +45,7 @@ public SqlServerStorageOptions() TransactionTimeout = TimeSpan.FromMinutes(1); DisableGlobalLocks = false; UsePageLocksOnDequeue = false; + NonBlockingFetchSql = true; } [Obsolete("TransactionIsolationLevel option is deprecated, please set UseRecommendedIsolationLevel instead. Will be removed in 2.0.0.")] @@ -122,5 +123,7 @@ public string SchemaName public bool UsePageLocksOnDequeue { get; set; } public bool UseRecommendedIsolationLevel { get; set; } public bool EnableHeavyMigrations { get; set; } + + public bool NonBlockingFetchSql { get; set; } } }