Skip to content

Commit

Permalink
Merge branch 'master' into feat/summary/allow-for-disabling-task-owne…
Browse files Browse the repository at this point in the history
…r-report-sender
  • Loading branch information
Jonathanio123 authored Dec 11, 2024
2 parents 3eea8d0 + 6cd9ae9 commit 8b30171
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ metadata:
name: summary-api-fusiondev-ingress
annotations:
kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-fusiondev-issuer
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-buffer-size: "32k"
nginx.org/client-max-body-size: "50m"
nginx.ingress.kubernetes.io/client-max-body-size: "50m"
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
spec:
ingressClassName: nginx
ingressClassName: ingress-nginx-fusiondev
tls:
- hosts:
- fra-summary.api.fusion-dev.net
Expand All @@ -36,14 +35,13 @@ metadata:
name: summary-api-equinor-ingress
annotations:
kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-buffer-size: "32k"
nginx.org/client-max-body-size: "50m"
nginx.ingress.kubernetes.io/client-max-body-size: "50m"
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
spec:
ingressClassName: nginx
ingressClassName: ingress-nginx-equinor
tls:
- hosts:
- fra-summary.api.fusion.equinor.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ public async Task RunAsync(
if (_departmentFilter.Length != 0)
departments = departments.Where(d => _departmentFilter.Any(df => d.FullDepartment!.Contains(df)));

logger.LogInformation("Found departments {Departments}", JsonConvert.SerializeObject(departments, Formatting.Indented));

var apiDepartments = new List<ApiResourceOwnerDepartment>();

foreach (var orgUnit in departments)
// Set up parallelism
var threadCount = 2;

await Parallel.ForEachAsync(departments, new ParallelOptions { MaxDegreeOfParallelism = threadCount }, async (orgUnit, cancellationToken) =>
{
var resourceOwners = orgUnit.Management.Persons
.Select(p => Guid.Parse(p.AzureUniqueId))
Expand All @@ -102,38 +103,42 @@ public async Task RunAsync(
.ToArray();

var recipients = resourceOwners.Concat(delegatedResponsibles).ToArray();

if (recipients.Length == 0)
{
logger.LogInformation("Skipping department {Department} as it has no resource owners or delegated responsibles", orgUnit.FullDepartment);
continue;
return;
}

apiDepartments.Add(new ApiResourceOwnerDepartment()
lock (apiDepartments)
{
DepartmentSapId = orgUnit.SapId!,
FullDepartmentName = orgUnit.FullDepartment!,
ResourceOwnersAzureUniqueId = resourceOwners,
DelegateResourceOwnersAzureUniqueId = delegatedResponsibles
});
}
apiDepartments.Add(new ApiResourceOwnerDepartment()
{
DepartmentSapId = orgUnit.SapId!,
FullDepartmentName = orgUnit.FullDepartment!,
ResourceOwnersAzureUniqueId = resourceOwners,
DelegateResourceOwnersAzureUniqueId = delegatedResponsibles
});
}
});

var enqueueTimeForDepartmentMapping = QueueTimeHelper.CalculateEnqueueTime(apiDepartments, _totalBatchTime, logger);

logger.LogInformation("Syncing departments {Departments}", JsonConvert.SerializeObject(enqueueTimeForDepartmentMapping, Formatting.Indented));


foreach (var department in apiDepartments)
await Parallel.ForEachAsync(apiDepartments, new ParallelOptions { MaxDegreeOfParallelism = threadCount }, async (department, cancellationToken) =>
{
try
{
//TODO: Do one batch update instead of individual updates
// TODO: Do one batch update instead of individual updates
// Update the database
await summaryApiClient.PutDepartmentAsync(department, cancellationToken);
}
catch (Exception e)
{
logger.LogCritical(e, "Failed to PUT department {Department}", JsonConvert.SerializeObject(department, Formatting.Indented));
continue;
logger.LogCritical(e, "Failed to PUT department {Department}",
JsonConvert.SerializeObject(department, Formatting.Indented));
return;
}

try
Expand All @@ -143,9 +148,11 @@ public async Task RunAsync(
}
catch (Exception e)
{
logger.LogCritical(e, "Failed to send department to queue {Department}", JsonConvert.SerializeObject(department, Formatting.Indented));
logger.LogCritical(e, "Failed to send department to queue {Department}",
JsonConvert.SerializeObject(department, Formatting.Indented));
}
}
});


logger.LogInformation("weekly-department-recipients-sync completed");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ metadata:
name: resources-api-fusion-ingress
annotations:
kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-fusiondev-issuer
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-buffer-size: "32k"
nginx.org/client-max-body-size: "50m"
nginx.ingress.kubernetes.io/client-max-body-size: "50m"
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
spec:
ingressClassName: nginx
ingressClassName: ingress-nginx-fusiondev
tls:
- hosts:
- fra-resources.api.fusion-dev.net
Expand All @@ -36,14 +35,13 @@ metadata:
name: resources-api-fusion-ingress
annotations:
kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-buffer-size: "32k"
nginx.org/client-max-body-size: "50m"
nginx.ingress.kubernetes.io/client-max-body-size: "50m"
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
spec:
ingressClassName: nginx
ingressClassName: ingress-nginx-equinor
tls:
- hosts:
- fra-resources.api.fusion.equinor.com
Expand Down

0 comments on commit 8b30171

Please sign in to comment.