-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #459 from TimeWarpEngineering/Cramer/2024-07-25/Next
StateInitializationPreProcessor
- Loading branch information
Showing
21 changed files
with
386 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Source/TimeWarp.State/Features/StateInitialization/StateInitializationPreProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace TimeWarp.State; | ||
Check warning on line 1 in Source/TimeWarp.State/Features/StateInitialization/StateInitializationPreProcessor.cs GitHub Actions / Qodana for .NETNamespace does not correspond to file location
|
||
|
||
public class StateInitializationPreProcessor<TRequest> : IRequestPreProcessor<TRequest> where TRequest : IAction | ||
{ | ||
private readonly IStore Store; | ||
private readonly ILogger<StateInitializationPreProcessor<TRequest>> Logger; | ||
|
||
public StateInitializationPreProcessor(IStore store, ILogger<StateInitializationPreProcessor<TRequest>> logger) | ||
{ | ||
Store = store; | ||
Logger = logger; | ||
} | ||
|
||
public async Task Process(TRequest request, CancellationToken cancellationToken) | ||
{ | ||
string typeName = typeof(TRequest).GetEnclosingStateType().FullName ?? throw new InvalidOperationException(); | ||
|
||
// Wait for the state initialization to complete before processing the action | ||
if (Store.StateInitializationTasks.TryGetValue(typeName, out Task? initializationTask)) | ||
{ | ||
try | ||
{ | ||
Logger.LogTrace | ||
( | ||
EventIds.StateInitializationPreProcessor_Waiting, | ||
"Waiting for state initialization to complete. State type: {StateType}", | ||
typeName | ||
); | ||
|
||
await initializationTask; | ||
|
||
Logger.LogTrace | ||
( | ||
EventIds.StateInitializationPreProcessor_Completed, | ||
"State initialization completed. State type: {StateType}", | ||
typeName | ||
); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.LogError(ex, "Error occurred while waiting for state initialization."); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.