Skip to content
Snippets Groups Projects
Commit 86a17cf7 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Fix: Added Request Wrapper to prevent SPARQL Timeouts

parent 65de903b
No related branches found
No related tags found
1 merge request!9Fix: Deploy only changed graphs
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<PackageReference Include="LibGit2Sharp" Version="0.26.2" /> <PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="NLog" Version="5.1.0" /> <PackageReference Include="NLog" Version="5.1.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.0" /> <PackageReference Include="NLog.Extensions.Logging" Version="5.2.0" />
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
using Polly;
namespace Coscine.GraphDeployer;
public static class Helpers
{
/// <summary>
/// Retry Virtuoso Requests since they sometimes just fail
/// </summary>
/// <typeparam name="W"></typeparam>
/// <param name="function"></param>
/// <returns></returns>
public static void WrapRequest(Action action)
{
Policy
.Handle<Exception>()
.WaitAndRetry(5, retryNumber => TimeSpan.FromMilliseconds(200))
.Execute(() => action.Invoke());
}
/// <summary>
/// Retry Virtuoso Requests since they sometimes just fail
/// </summary>
/// <typeparam name="W"></typeparam>
/// <param name="function"></param>
/// <returns></returns>
public static W WrapRequest<W>(Func<W> function)
{
return Policy
.Handle<Exception>()
.WaitAndRetry(5, retryNumber => TimeSpan.FromMilliseconds(200))
.ExecuteAndCapture(() => function.Invoke()).Result;
}
}
...@@ -112,7 +112,7 @@ public class Program ...@@ -112,7 +112,7 @@ public class Program
var graph = kv.Value.Item1; var graph = kv.Value.Item1;
var graphName = kv.Key.ToString(); var graphName = kv.Key.ToString();
var currentGraph = _rdfStoreConnector.GetGraph(graphName); var currentGraph = Helpers.WrapRequest(() => _rdfStoreConnector.GetGraph(graphName));
var graphWasChanged = graph.Triples.Count != currentGraph.Triples.Count var graphWasChanged = graph.Triples.Count != currentGraph.Triples.Count
|| graph.Triples.Any((triple) => !currentGraph.Triples.Any((currentTriple) => || graph.Triples.Any((triple) => !currentGraph.Triples.Any((currentTriple) =>
...@@ -124,7 +124,7 @@ public class Program ...@@ -124,7 +124,7 @@ public class Program
{ {
if (!currentGraph.IsEmpty) if (!currentGraph.IsEmpty)
{ {
_rdfStoreConnector.ClearGraph(graphName); Helpers.WrapRequest(() => _rdfStoreConnector.ClearGraph(graphName));
_logger.LogInformation("Cleared Graph {graphName}", graphName); _logger.LogInformation("Cleared Graph {graphName}", graphName);
} }
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment