Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • coscine/backend/scripts/kpi-generator
1 result
Select Git revision
Loading items
Show changes
Commits on Source (3)
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<AssemblyName>Coscine.KpiGenerator</AssemblyName> <AssemblyName>Coscine.KpiGenerator</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Version>0.1.9</Version> <Version>0.1.10</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
<PackageReference Include="GitLabApiClient" Version="1.8.1-beta.5" /> <PackageReference Include="GitLabApiClient" Version="1.8.1-beta.5" />
<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>
......
...@@ -57,7 +57,7 @@ public class Program ...@@ -57,7 +57,7 @@ public class Program
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
_logger.LogError(e, e.Message); _logger.LogWarning(e, e.Message);
return -1; // Exit Code -1 for Failure return -1; // Exit Code -1 for Failure
} }
} }
...@@ -129,7 +129,7 @@ public class Program ...@@ -129,7 +129,7 @@ public class Program
{ {
if (ex.InnerException is not null) if (ex.InnerException is not null)
{ {
_logger.LogError(ex.InnerException, "InnerException: {innerException}", ex.InnerException.Message); _logger.LogWarning(ex.InnerException, "InnerException: {innerException}", ex.InnerException.Message);
LogInnerException(ex.InnerException); LogInnerException(ex.InnerException);
} }
} }
......
...@@ -5,6 +5,7 @@ using GitLabApiClient; ...@@ -5,6 +5,7 @@ using GitLabApiClient;
using GitLabApiClient.Models.Branches.Requests; using GitLabApiClient.Models.Branches.Requests;
using GitLabApiClient.Models.Commits.Requests.CreateCommitRequest; using GitLabApiClient.Models.Commits.Requests.CreateCommitRequest;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Polly;
using System.Text; using System.Text;
using System.Web; using System.Web;
using VDS.RDF.Query; using VDS.RDF.Query;
...@@ -154,7 +155,7 @@ public abstract class Reporting<O> where O : class ...@@ -154,7 +155,7 @@ public abstract class Reporting<O> where O : class
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
_logger.LogError(e, e.Message); _logger.LogWarning(e, e.Message);
return false; return false;
} }
} }
...@@ -173,7 +174,7 @@ public abstract class Reporting<O> where O : class ...@@ -173,7 +174,7 @@ public abstract class Reporting<O> where O : class
} }
else else
{ {
var organizationTriples = RdfStoreConnector.GetLabelForSubject(new Uri(Uri.UnescapeDataString(rorUrl))).ToList(); var organizationTriples = WrapRequest(() => RdfStoreConnector.GetLabelForSubject(new Uri(Uri.UnescapeDataString(rorUrl))).ToList());
if (organizationTriples.Any()) if (organizationTriples.Any())
{ {
result = new Organization result = new Organization
...@@ -261,4 +262,33 @@ public abstract class Reporting<O> where O : class ...@@ -261,4 +262,33 @@ public abstract class Reporting<O> where O : class
} }
Console.WriteLine(); Console.WriteLine();
} }
/// <summary>
/// Retry Virtuoso Requests since they sometimes just fail
/// </summary>
/// <typeparam name="W"></typeparam>
/// <param name="function"></param>
/// <returns></returns>
public 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 W WrapRequest<W>(Func<W> function)
{
return Policy
.Handle<Exception>()
.WaitAndRetry(5, retryNumber => TimeSpan.FromMilliseconds(200))
.ExecuteAndCapture(() => function.Invoke()).Result;
}
} }
\ No newline at end of file
...@@ -53,7 +53,7 @@ public class ApplicationProfileReporting : Reporting<ApplicationProfileReporting ...@@ -53,7 +53,7 @@ public class ApplicationProfileReporting : Reporting<ApplicationProfileReporting
OPTIONAL {{ ?{_applicationProfile} dcterms:{_license} ?{_license} . }} OPTIONAL {{ ?{_applicationProfile} dcterms:{_license} ?{_license} . }}
}}" }}"
}; };
using var result = RdfStoreConnector.QueryEndpoint.QueryWithResultSet(queryString.ToString()); using var result = WrapRequest(() => RdfStoreConnector.QueryEndpoint.QueryWithResultSet(queryString.ToString()));
var grouped = result.GroupBy(ap => new var grouped = result.GroupBy(ap => new
{ {
......
...@@ -29,7 +29,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions> ...@@ -29,7 +29,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine($"!! Skipping ProjectReporting: {e.Message} \n"); Console.WriteLine($"!! Skipping ProjectReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping ProjectReporting: {message}", e.Message); _logger.LogError(e, "Skipping ProjectReporting: {message}", e.Message);
} }
// Resource Reporting // Resource Reporting
...@@ -43,7 +43,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions> ...@@ -43,7 +43,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine($"!! Skipping ResourceReporting: {e.Message} \n"); Console.WriteLine($"!! Skipping ResourceReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping ResourceReporting: {message}", e.Message); _logger.LogError(e, "Skipping ResourceReporting: {message}", e.Message);
} }
// User Reporting // User Reporting
...@@ -57,7 +57,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions> ...@@ -57,7 +57,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine($"!! Skipping UserReporting: {e.Message} \n"); Console.WriteLine($"!! Skipping UserReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping UserReporting: {message}", e.Message); _logger.LogError(e, "Skipping UserReporting: {message}", e.Message);
} }
// Application Profile Reporting // Application Profile Reporting
...@@ -71,7 +71,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions> ...@@ -71,7 +71,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine($"!! Skipping ApplicationProfileReporting: {e.Message} \n"); Console.WriteLine($"!! Skipping ApplicationProfileReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping ApplicationProfileReporting: {message}", e.Message); _logger.LogError(e, "Skipping ApplicationProfileReporting: {message}", e.Message);
} }
// System Status Reporting // System Status Reporting
...@@ -85,7 +85,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions> ...@@ -85,7 +85,7 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine($"!! Skipping SystemReporting: {e.Message} \n"); Console.WriteLine($"!! Skipping SystemReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping SystemReporting: {message}", e.Message); _logger.LogError(e, "Skipping SystemReporting: {message}", e.Message);
} }
return result; return result;
......
...@@ -164,7 +164,7 @@ public class ProjectReporting : Reporting<ProjectReportingOptions> ...@@ -164,7 +164,7 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, ex.Message); _logger.LogWarning(ex, ex.Message);
return 0f; return 0f;
} }
} }
...@@ -198,7 +198,7 @@ public class ProjectReporting : Reporting<ProjectReportingOptions> ...@@ -198,7 +198,7 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, ex.Message); _logger.LogWarning(ex, ex.Message);
return 0f; return 0f;
} }
} }
......
...@@ -135,7 +135,7 @@ public class ResourceReporting : Reporting<ResourceReportingOptions> ...@@ -135,7 +135,7 @@ public class ResourceReporting : Reporting<ResourceReportingOptions>
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error: {message} for {@resource}", ex.Message, resource); _logger.LogWarning(ex, "Error: {message} for {@resource}", ex.Message, resource);
return null; return null;
} }
} }
......
...@@ -245,7 +245,7 @@ public class UserReporting : Reporting<UserReportingOptions> ...@@ -245,7 +245,7 @@ public class UserReporting : Reporting<UserReportingOptions>
}} }}
" "
}; };
using var results = RdfStoreConnector.QueryEndpoint.QueryWithResultSet(_queryString.ToString()); using var results = WrapRequest(() => RdfStoreConnector.QueryEndpoint.QueryWithResultSet(_queryString.ToString()));
if (!results.IsEmpty) if (!results.IsEmpty)
{ {
var ror = results.Select(x => x.Value("ror").ToString()); // Get the value for ?ror var ror = results.Select(x => x.Value("ror").ToString()); // Get the value for ?ror
...@@ -279,7 +279,7 @@ public class UserReporting : Reporting<UserReportingOptions> ...@@ -279,7 +279,7 @@ public class UserReporting : Reporting<UserReportingOptions>
}} }}
" "
}; };
using var results = RdfStoreConnector.QueryEndpoint.QueryWithResultSet(_queryString.ToString()); using var results = WrapRequest(() => RdfStoreConnector.QueryEndpoint.QueryWithResultSet(_queryString.ToString()));
if (!results.IsEmpty) if (!results.IsEmpty)
{ {
var ror = results.Select(x => x.Value("ror").ToString()); // Get the value for ?ror var ror = results.Select(x => x.Value("ror").ToString()); // Get the value for ?ror
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
<targets> <targets>
<!-- Write logs to File --> <!-- Write logs to File -->
<target xsi:type="File" name="fileLog" fileName="C:/coscine/logs/${assembly-name}/${assembly-version}/log-${shortdate}.log" > <target xsi:type="File" name="fileLog" fileName="C:/coscine/logs/${assembly-name}/${assembly-version}/log-${shortdate}.log" >
<layout xsi:type="CompoundLayout">
<layout xsi:type="JsonLayout" EscapeForwardSlash="true"> <layout xsi:type="JsonLayout" EscapeForwardSlash="true">
<attribute layout="${longdate}" name="Timestamp"/> <attribute layout="${longdate}" name="Timestamp"/>
<attribute layout="${level:upperCase=true}" name="Level"/> <attribute layout="${level:upperCase=true}" name="Level"/>
...@@ -20,8 +19,6 @@ ...@@ -20,8 +19,6 @@
<layout xsi:type='JsonLayout' includeAllProperties="true" maxRecursionLimit="2"/> <layout xsi:type='JsonLayout' includeAllProperties="true" maxRecursionLimit="2"/>
</attribute> </attribute>
</layout> </layout>
<layout xsi:type='SimpleLayout' text="," />
</layout>
</target> </target>
</targets> </targets>
......