Skip to content

Commit

Permalink
Don't log warnings regarding scheduler parallelism too often
Browse files Browse the repository at this point in the history
  • Loading branch information
odinserj committed Apr 3, 2024
1 parent 1b9d593 commit ead95d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Hangfire.Core/BackgroundJobServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,14 @@ private IEnumerable<IBackgroundProcessDispatcherBuilder> GetRequiredProcesses(

if (!_options.IsLightweightServer)
{
processes.Add(new DelayedJobScheduler(_options.SchedulePollingInterval, stateChanger).UseBackgroundPool(1));
processes.Add(
new DelayedJobScheduler(_options.SchedulePollingInterval, stateChanger)
{
TaskScheduler = _options.TaskScheduler,
MaxDegreeOfParallelism = _options.MaxDegreeOfParallelismForSchedulers
}
.UseBackgroundPool(1));

processes.Add(
new RecurringJobScheduler(factory, _options.SchedulePollingInterval, timeZoneResolver)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Hangfire.Core/Server/DelayedJobScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class DelayedJobScheduler : IBackgroundProcess
private readonly IBackgroundJobStateChanger _stateChanger;
private readonly IProfiler _profiler;
private readonly TimeSpan _pollingDelay;
private bool _parallelismIssueLogged;

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

for (var i = 0; i < BatchSize; i++)
Expand Down
4 changes: 3 additions & 1 deletion src/Hangfire.Core/Server/RecurringJobScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class RecurringJobScheduler : IBackgroundProcess
private readonly ITimeZoneResolver _timeZoneResolver;
private readonly TimeSpan _pollingDelay;
private readonly IProfiler _profiler;
private bool _parallelismIssueLogged;

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

for (var i = 0; i < BatchSize; i++)
Expand Down

0 comments on commit ead95d1

Please sign in to comment.