public async Task ProcessAsync(JToken argumentToken) { // This method is called asynchronously whenever a new build is inserted in BAR. // It's goal is to compute the incoherent dependencies that the build have and // persist the list of them in BAR. int buildId = argumentToken.Value <int>(); DependencyGraphBuildOptions graphBuildOptions = new DependencyGraphBuildOptions() { IncludeToolset = false, LookupBuilds = false, NodeDiff = NodeDiff.None }; try { Data.Models.Build build = await _context.Builds.FindAsync(buildId); DependencyGraph graph = await DependencyGraph.BuildRemoteDependencyGraphAsync( _remoteFactory, build.GitHubRepository ?? build.AzureDevOpsRepository, build.Commit, graphBuildOptions, _logger); var incoherencies = new List <Data.Models.BuildIncoherence>(); foreach (var incoherence in graph.IncoherentDependencies) { incoherencies.Add(new Data.Models.BuildIncoherence { Name = incoherence.Name, Version = incoherence.Version, Repository = incoherence.RepoUri, Commit = incoherence.Commit }); } _context.Entry(build).Reload(); build.Incoherencies = incoherencies; _context.Builds.Update(build); await _context.SaveChangesAsync(); } catch (Exception e) { _logger.LogWarning(e, $"Problems computing the dependency incoherencies for BAR build {buildId}"); } }
/// <summary> /// This method is called asynchronously whenever a new build is inserted in BAR. /// It's goal is to compute the incoherent dependencies that the build have and /// persist the list of them in BAR. /// </summary> /// <param name="buildId">Build id for which the incoherencies should be computed.</param> private async Task SetBuildIncoherencyInfoAsync(int buildId) { DependencyGraphBuildOptions graphBuildOptions = new DependencyGraphBuildOptions() { IncludeToolset = false, LookupBuilds = false, NodeDiff = NodeDiff.None }; try { using (IServiceScope scope = ServiceScopeFactory.CreateScope()) { BuildAssetRegistryContext context = scope.ServiceProvider.GetRequiredService <BuildAssetRegistryContext>(); Data.Models.Build build = await context.Builds.FindAsync(buildId); DependencyGraph graph = await DependencyGraph.BuildRemoteDependencyGraphAsync( RemoteFactory, build.GitHubRepository ?? build.AzureDevOpsRepository, build.Commit, graphBuildOptions, Logger); var incoherencies = new List <Data.Models.BuildIncoherence>(); foreach (var incoherence in graph.IncoherentDependencies) { build.Incoherencies.Add(new Data.Models.BuildIncoherence { Name = incoherence.Name, Version = incoherence.Version, Repository = incoherence.RepoUri, Commit = incoherence.Commit }); } context.Entry <Data.Models.Build>(build).Reload(); build.Incoherencies = incoherencies; context.Builds.Update(build); await context.SaveChangesAsync(); } } catch (Exception e) { Logger.LogWarning(e, $"Problems computing the dependency incoherencies for BAR build {buildId}"); } }