Skip to content

Commit

Permalink
Cache immutable arrays in the Worker class
Browse files Browse the repository at this point in the history
  • Loading branch information
odinserj committed Jun 20, 2024
1 parent 084d85b commit e1f9e12
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Hangfire.Core/Server/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class Worker : IBackgroundProcess
public static readonly string TransactionalAcknowledgePrefix = JobStorageFeatures.TransactionalAcknowledgePrefix;

private static readonly ConcurrentDictionary<Guid, string> WorkerGuidCache = new();
private static readonly string[] EligibleWorkerStates = new[] { EnqueuedState.StateName, ScheduledState.StateName, ProcessingState.StateName };
private static readonly string[] ProcessingStateArray = new[] { ProcessingState.StateName };

private readonly TimeSpan _jobInitializationWaitTimeout;
private readonly int _maxStateChangeAttempts;
Expand Down Expand Up @@ -123,7 +125,7 @@ public void Execute(BackgroundProcessContext context)
fetchedJob.JobId,
processingState,
null,
new[] { EnqueuedState.StateName, ScheduledState.StateName, ProcessingState.StateName },
EligibleWorkerStates,
null,
out backgroundJob,
linkedCts.Token,
Expand Down Expand Up @@ -157,7 +159,7 @@ public void Execute(BackgroundProcessContext context)
fetchedJob.JobId,
state,
customData,
new[] { ProcessingState.StateName },
ProcessingStateArray,
transactionalAck ? fetchedJob : null,
out _,
CancellationToken.None,
Expand Down

0 comments on commit e1f9e12

Please sign in to comment.