Add JobStateManager for thread-safe job state tracking
Introduced JobStateManager class to manage job states using a ConcurrentDictionary, supporting thread-safe get/set operations per job type. Added State enum with Running and Stopped values. Allows optional initial state dictionary for job states.
This commit is contained in:
19
EnvelopeGenerator.ServiceHost/Jobs/JobStateManager.cs
Normal file
19
EnvelopeGenerator.ServiceHost/Jobs/JobStateManager.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using AngleSharp.Common;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||
|
||||
public class JobStateManager(Dictionary<string, State>? initialState = null)
|
||||
{
|
||||
private readonly ConcurrentDictionary<Type, State> _states = new();
|
||||
|
||||
public State GetState<TJob>() => _states.GetOrAdd(typeof(TJob), type => initialState?.GetOrDefault(type.Name, State.Stopped) ?? State.Stopped);
|
||||
|
||||
public State SetState<TJob>(State state) => _states[typeof(TJob)] = state;
|
||||
}
|
||||
|
||||
public enum State
|
||||
{
|
||||
Running,
|
||||
Stopped
|
||||
}
|
||||
Reference in New Issue
Block a user