From 2dadefecc55cdfd5f677a8d521aaa56bfe652bdb Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 13 Apr 2026 16:28:40 +0200 Subject: [PATCH] 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. --- .../Jobs/JobStateManager.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 EnvelopeGenerator.ServiceHost/Jobs/JobStateManager.cs diff --git a/EnvelopeGenerator.ServiceHost/Jobs/JobStateManager.cs b/EnvelopeGenerator.ServiceHost/Jobs/JobStateManager.cs new file mode 100644 index 00000000..fa298698 --- /dev/null +++ b/EnvelopeGenerator.ServiceHost/Jobs/JobStateManager.cs @@ -0,0 +1,19 @@ +using AngleSharp.Common; +using System.Collections.Concurrent; + +namespace EnvelopeGenerator.ServiceHost.Jobs; + +public class JobStateManager(Dictionary? initialState = null) +{ + private readonly ConcurrentDictionary _states = new(); + + public State GetState() => _states.GetOrAdd(typeof(TJob), type => initialState?.GetOrDefault(type.Name, State.Stopped) ?? State.Stopped); + + public State SetState(State state) => _states[typeof(TJob)] = state; +} + +public enum State +{ + Running, + Stopped +} \ No newline at end of file