Skip to content

Commit

Permalink
Parallel execution when release already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanthkb committed Jan 12, 2025
1 parent 1adcbf5 commit e50be28
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/LCT.SW360PackageCreator/ComponentCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
// --------------------------------------------------------------------------------------------------------------------

using CycloneDX.Models;
using JetBrains.Annotations;
using LCT.APICommunications;
using LCT.APICommunications.Model;
using LCT.APICommunications.Model.Foss;
using LCT.Common;
using LCT.Common.Constants;
using LCT.Common.Interface;
using LCT.Common.Model;
using LCT.Services;
using LCT.Services.Interface;
using LCT.Services.Model;
using LCT.SW360PackageCreator.Interfaces;
Expand Down Expand Up @@ -116,6 +118,7 @@ private async Task<List<Components>> GetListOfBomData(List<Component> components
{
MaxDegreeOfParallelism = Dataconstant.MaxDegreeOfParallelism
};

await ProcessAsyncHelper.ProcessItemsAsync(components, action, parallelOptions);
return lstOfBomDataToBeCompared;
}
Expand Down Expand Up @@ -289,11 +292,36 @@ private async Task CreateComponent(ICreatorHelper creatorHelper,

try
{
foreach (ComparisonBomData item in componentsToBoms)
List<ComparisonBomData> comparisonBomsForMixed = componentsToBoms.Where(avl => (avl.ComponentStatus == Dataconstant.Available && avl.ReleaseStatus == Dataconstant.NotAvailable)
|| (avl.ComponentStatus == Dataconstant.NotAvailable && avl.ReleaseStatus == Dataconstant.NotAvailable)).ToList();
// Getting the list of components & releases are avilable
List<ComparisonBomData> comparisonBomsForAvilables = componentsToBoms.Where(avl=> avl.ComponentStatus == Dataconstant.Available && avl.ReleaseStatus == Dataconstant.Available).ToList();

foreach (ComparisonBomData item in comparisonBomsForMixed)
{
await CreateComponentAndRealease(creatorHelper, sw360CreatorService, item, sw360Url, appSettings);
}

//Processing parallely for existing components
Func<ComparisonBomData, CancellationToken, ValueTask> action = async (item, ct) =>
{
try
{
await ComponentAndReleaseAvailable(item, sw360Url, sw360CreatorService, appSettings);
}
catch (Exception ex)
{
Logger.Error($"CreateComponent() : Error processing item {item.Name}: {ex.Message}", ex);
}
};

var parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = Dataconstant.MaxDegreeOfParallelism
};
await ProcessAsyncHelper.ProcessItemsAsync(comparisonBomsForAvilables, action, parallelOptions);


if (appSettings.ProjectType.ToUpperInvariant() == "ALPINE")
{
string localPathforSourceRepo = UrlHelper.GetDownloadPathForAlpineRepo();
Expand Down Expand Up @@ -353,8 +381,6 @@ private async Task CreateComponentAndRealease(ICreatorHelper creatorHelper,
await CreateComponentAndReleaseWhenNotAvailable(item, sw360CreatorService, creatorHelper, appSettings);

await CreateReleaseWhenNotAvailable(item, sw360CreatorService, creatorHelper, appSettings);

await ComponentAndReleaseAvailable(item, sw360Url, sw360CreatorService, appSettings);
}

private async Task CreateComponentAndReleaseWhenNotAvailable(ComparisonBomData item,
Expand Down

0 comments on commit e50be28

Please sign in to comment.