Files
EnvelopeGenerator/EnvelopeGenerator.ServiceHost/Jobs/JobStateManager.cs
TekH 2dadefecc5 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.
2026-04-13 16:28:40 +02:00

19 lines
539 B
C#

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
}