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.
19 lines
539 B
C#
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
|
|
} |