Applies mutex in codex CidChecker

This commit is contained in:
Ben 2024-12-03 08:50:50 +01:00
parent ac8f01c922
commit 33153a2b76
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
1 changed files with 6 additions and 0 deletions

View File

@ -10,6 +10,7 @@ namespace BiblioTech
private static readonly string nl = Environment.NewLine; private static readonly string nl = Environment.NewLine;
private readonly Configuration config; private readonly Configuration config;
private readonly ILog log; private readonly ILog log;
private readonly Mutex checkMutex = new Mutex();
private CodexApi? currentCodexNode; private CodexApi? currentCodexNode;
public CodexCidChecker(Configuration config, ILog log) public CodexCidChecker(Configuration config, ILog log)
@ -27,6 +28,7 @@ namespace BiblioTech
try try
{ {
checkMutex.WaitOne();
var codex = GetCodex(); var codex = GetCodex();
var nodeCheck = await CheckCodex(codex); var nodeCheck = await CheckCodex(codex);
if (!nodeCheck) return new CheckResponse(false, "Codex node is not available. Cannot perform check.", $"Codex node at '{config.CodexEndpoint}' did not respond correctly to debug/info."); if (!nodeCheck) return new CheckResponse(false, "Codex node is not available. Cannot perform check.", $"Codex node at '{config.CodexEndpoint}' did not respond correctly to debug/info.");
@ -37,6 +39,10 @@ namespace BiblioTech
{ {
return new CheckResponse(false, "Internal server error", ex.ToString()); return new CheckResponse(false, "Internal server error", ex.ToString());
} }
finally
{
checkMutex.ReleaseMutex();
}
} }
private async Task<CheckResponse> PerformCheck(CodexApi codex, string cid) private async Task<CheckResponse> PerformCheck(CodexApi codex, string cid)