Skip to content

Commit

Permalink
Merge branch 'master' into chore/resources/remove-summary-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathanio123 authored Dec 18, 2024
2 parents 21e6d67 + ad5f41c commit 1ec6469
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 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 @@ -28,6 +28,9 @@ public class WeeklyTaskOwnerReportSender
private readonly bool sendingNotificationEnabled = true; // Default to true so that we don't accidentally disable sending notifications
private readonly string fusionUri;

private const string IsSendingNotificationEnabledKey = "WeeklyTaskOwnerReport_IsSendingNotificationEnabled";
private const string FunctionName = "weekly-task-owner-report-sender";

public WeeklyTaskOwnerReportSender(ILogger<WeeklyTaskOwnerReportSender> logger, IConfiguration configuration, ISummaryApiClient summaryApiClient, IMailApiClient mailApiClient, IPeopleApiClient peopleApiClient, IContextApiClient contextApiClient)
{
this.logger = logger;
Expand All @@ -39,14 +42,12 @@ public WeeklyTaskOwnerReportSender(ILogger<WeeklyTaskOwnerReportSender> logger,
fusionUri = (configuration["Endpoints_portal"] ?? "https://fusion.equinor.com/").TrimEnd('/');

// Need to explicitly add the configuration key to the app settings to disable sending of notifications
if (int.TryParse(configuration["isSendingNotificationEnabled"], out var enabled))
if (int.TryParse(configuration[IsSendingNotificationEnabledKey], out var enabled))
sendingNotificationEnabled = enabled == 1;
else if (bool.TryParse(configuration["isSendingNotificationEnabled"], out var enabledBool))
else if (bool.TryParse(configuration[IsSendingNotificationEnabledKey], out var enabledBool))
sendingNotificationEnabled = enabledBool;
}

private const string FunctionName = "weekly-task-owner-report-sender";

[FunctionName(FunctionName)]
public async Task RunAsync([TimerTrigger("0 0 5 * * MON", RunOnStartup = false)] TimerInfo timerInfo, CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -287,8 +288,8 @@ private SendEmailWithTemplateRequest CreateReportMail(string[] recipients, Proje
}
}, new GoToAction()
{
Title = "Go to position overview",
Url = $"{fusionUri}/apps/org-admin/{contextId}/edit-positions/listing-view"
Title = "Go to positions listing view",
Url = $"{fusionUri}/apps/org-admin/{contextId}/edit-positions/listing-view?filter=allocations-exp-3m"
})
.AddGrid("TBN positions with start date next 3 months", "(Please create a resource request or update the position start-date)", new List<GridColumn>()
{
Expand All @@ -314,7 +315,7 @@ private SendEmailWithTemplateRequest CreateReportMail(string[] recipients, Proje
}
}, new GoToAction()
{
Title = "Go to position overview",
Title = "Go to positions listing view",
Url = $"{fusionUri}/apps/org-admin/{contextId}/edit-positions/listing-view?filter=tbn-pos-3m"
})
.Build();
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 1ec6469

Please sign in to comment.