Skip to content

Commit fb35d3f

Browse files
committed
Reduce DelayedJobSchedulerFacts execution time
1 parent e37610e commit fb35d3f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Diff for: src/Hangfire.Core/Server/DelayedJobScheduler.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public DelayedJobScheduler(TimeSpan pollingDelay, [NotNull] IBackgroundJobStateC
134134
/// </summary>
135135
public TaskScheduler TaskScheduler { get; set; }
136136

137+
internal Func<int, TimeSpan> RetryDelayFunc { get; set; } = attempt => TimeSpan.FromSeconds(attempt);
138+
137139
/// <inheritdoc />
138140
public void Execute(BackgroundProcessContext context)
139141
{
@@ -341,7 +343,7 @@ private void EnqueueBackgroundJob(BackgroundProcessContext context, IStorageConn
341343
exception = ex;
342344
}
343345

344-
context.Wait(TimeSpan.FromSeconds(retryAttempt));
346+
context.Wait(RetryDelayFunc(retryAttempt));
345347
}
346348

347349
_logger.ErrorException(

Diff for: tests/Hangfire.Core.Tests/Server/DelayedJobSchedulerFacts.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ public void Execute_MovesJobToTheFailedState_WithFiltersDisabled_WhenStateChange
226226
.Throws<InvalidOperationException>();
227227

228228
var scheduler = CreateScheduler();
229-
229+
scheduler.RetryDelayFunc = _ => TimeSpan.FromMilliseconds(50);
230+
230231
// Act
231232
scheduler.Execute(_context.Object);
232233

0 commit comments

Comments
 (0)