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:
2026-04-13 16:28:40 +02:00
parent 162f066b08
commit 2dadefecc5

View 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
}