Skip to content

Commit ead95d1

Browse files
committed
Don't log warnings regarding scheduler parallelism too often
1 parent 1b9d593 commit ead95d1

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Hangfire.Core/BackgroundJobServer.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,14 @@ private IEnumerable<IBackgroundProcessDispatcherBuilder> GetRequiredProcesses(
213213

214214
if (!_options.IsLightweightServer)
215215
{
216-
processes.Add(new DelayedJobScheduler(_options.SchedulePollingInterval, stateChanger).UseBackgroundPool(1));
216+
processes.Add(
217+
new DelayedJobScheduler(_options.SchedulePollingInterval, stateChanger)
218+
{
219+
TaskScheduler = _options.TaskScheduler,
220+
MaxDegreeOfParallelism = _options.MaxDegreeOfParallelismForSchedulers
221+
}
222+
.UseBackgroundPool(1));
223+
217224
processes.Add(
218225
new RecurringJobScheduler(factory, _options.SchedulePollingInterval, timeZoneResolver)
219226
{

src/Hangfire.Core/Server/DelayedJobScheduler.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class DelayedJobScheduler : IBackgroundProcess
8181
private readonly IBackgroundJobStateChanger _stateChanger;
8282
private readonly IProfiler _profiler;
8383
private readonly TimeSpan _pollingDelay;
84+
private bool _parallelismIssueLogged;
8485

8586
/// <summary>
8687
/// Initializes a new instance of the <see cref="DelayedJobScheduler"/>
@@ -234,9 +235,10 @@ private int EnqueueNextScheduledJobs(BackgroundProcessContext context)
234235
}
235236
else
236237
{
237-
if (MaxDegreeOfParallelism > 1)
238+
if (MaxDegreeOfParallelism > 1 && !_parallelismIssueLogged)
238239
{
239240
_logger.Warn("Parallel execution is configured but can't be used, because current storage implementation doesn't support batching.");
241+
_parallelismIssueLogged = true;
240242
}
241243

242244
for (var i = 0; i < BatchSize; i++)

src/Hangfire.Core/Server/RecurringJobScheduler.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class RecurringJobScheduler : IBackgroundProcess
7878
private readonly ITimeZoneResolver _timeZoneResolver;
7979
private readonly TimeSpan _pollingDelay;
8080
private readonly IProfiler _profiler;
81+
private bool _parallelismIssueLogged;
8182

8283
/// <summary>
8384
/// Initializes a new instance of the <see cref="RecurringJobScheduler"/>
@@ -252,9 +253,10 @@ private int EnqueueNextRecurringJobs(BackgroundProcessContext context)
252253
}
253254
else
254255
{
255-
if (MaxDegreeOfParallelism > 1)
256+
if (MaxDegreeOfParallelism > 1 && !_parallelismIssueLogged)
256257
{
257258
_logger.Warn("Parallel execution is configured but can't be used, because current storage implementation doesn't support batching.");
259+
_parallelismIssueLogged = true;
258260
}
259261

260262
for (var i = 0; i < BatchSize; i++)

0 commit comments

Comments
 (0)