Skip to content

Commit

Permalink
(fix)Functions: API client timeout (#602)
Browse files Browse the repository at this point in the history
- [ ] ~~New feature~~
- [x] Bug fix
- [ ] ~~High impact~~

**Description of work:**
Some of the apicalls timed out after 100 sec. Solved by extending the
api-client timeout to five minuets.

**Testing:**
- [ ] ~~Can be tested~~
- [ ] ~~Automatic tests created / updated~~
- [ ] ~~Local tests are passing~~



**Checklist:**
- [ ] ~~Considered automated tests~~
- [ ] ~~Considered updating specification / documentation~~
- [ ] ~~Considered work items~~ 
- [ ] ~~Considered security~~
- [ ] ~~Performed developer testing~~
- [ ] ~~Checklist finalized / ready for review~~
  • Loading branch information
BouVid authored Nov 6, 2023
1 parent a1347c5 commit 9a81266
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
Expand All @@ -15,6 +16,7 @@ public class LineOrgApiClient : ILineOrgApiClient
public LineOrgApiClient(IHttpClientFactory httpClientFactory)
{
lineOrgClient = httpClientFactory.CreateClient(HttpClientNames.Application.LineOrg);
lineOrgClient.Timeout = TimeSpan.FromMinutes(5);
}

public async Task<IEnumerable<string>> GetOrgUnitDepartmentsAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class NotificationApiClient : INotificationApiClient
public NotificationApiClient(IHttpClientFactory httpClientFactory)
{
_client = httpClientFactory.CreateClient(HttpClientNames.Application.Notifications);
_client.Timeout = TimeSpan.FromMinutes(5);
}

public async Task<bool> SendNotification(SendNotificationsRequest request, Guid azureUniqueId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public class PeopleApiClient : IPeopleApiClient
public PeopleApiClient(IHttpClientFactory httpClientFactory)
{
peopleClient = httpClientFactory.CreateClient(HttpClientNames.Application.People);
peopleClient.Timeout = TimeSpan.FromMinutes(5);
}

public async Task<string> GetPersonFullDepartmentAsync(Guid? personAzureUniqueId)
{
var data = await peopleClient.GetAsJsonAsync<IResourcesApiClient.Person>($"persons/{personAzureUniqueId}?api-version=3.0");
var data = await peopleClient.GetAsJsonAsync<IResourcesApiClient.Person>(
$"persons/{personAzureUniqueId}?api-version=3.0");

return data.FullDepartment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class ResourcesApiClient : IResourcesApiClient
public ResourcesApiClient(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory)
{
resourcesClient = httpClientFactory.CreateClient(HttpClientNames.Application.Resources);
resourcesClient.Timeout = System.TimeSpan.FromMinutes(5);
log = loggerFactory.CreateLogger<ResourcesApiClient>();
}

Expand All @@ -27,37 +28,40 @@ public async Task<IEnumerable<ProjectReference>> GetProjectsAsync()
return await resourcesClient.GetAsJsonAsync<IEnumerable<ProjectReference>>("projects");
}

public async Task<IEnumerable<ResourceAllocationRequest>> GetIncompleteDepartmentAssignedResourceAllocationRequestsForProjectAsync(ProjectReference project)
public async Task<IEnumerable<ResourceAllocationRequest>>
GetIncompleteDepartmentAssignedResourceAllocationRequestsForProjectAsync(ProjectReference project)
{
var data = await resourcesClient.GetAsJsonAsync<InternalCollection<ResourceAllocationRequest>>(
$"projects/{project.Id}/resources/requests/?$filter=state.IsComplete eq false and isDraft eq false&$expand=orgPosition,orgPositionInstance&$top={int.MaxValue}");

return data.Value.Where(x => x.AssignedDepartment is not null);
}

public async Task<IEnumerable<ResourceAllocationRequest>> GetAllRequestsForDepartment(string departmentIdentifier)
public async Task<IEnumerable<ResourceAllocationRequest>> GetAllRequestsForDepartment(
string departmentIdentifier)
{
var response = await resourcesClient.GetAsJsonAsync<InternalCollection<ResourceAllocationRequest>>(
$"departments/{departmentIdentifier}/resources/requests?$expand=orgPosition,orgPositionInstance,actions");

return response.Value.ToList();
}

public async Task<IEnumerable<InternalPersonnelPerson>> GetAllPersonnelForDepartment(string departmentIdentifier)
public async Task<IEnumerable<InternalPersonnelPerson>> GetAllPersonnelForDepartment(
string departmentIdentifier)
{
var response = await resourcesClient.GetAsJsonAsync<InternalCollection<InternalPersonnelPerson>>(
$"departments/{departmentIdentifier}/resources/personnel?api-version=2.0&$includeCurrentAllocations=true");

return response.Value.ToList();

}

public async Task<bool> ReassignRequestAsync(ResourceAllocationRequest item, string? department)
{
var content = JsonConvert.SerializeObject(new { AssignedDepartment = department });
var stringContent = new StringContent(content, Encoding.UTF8, "application/json");

var result = await resourcesClient.PatchAsync($"/projects/{item.OrgPosition!.ProjectId}/requests/{item.Id}", stringContent);
var result = await resourcesClient.PatchAsync($"/projects/{item.OrgPosition!.ProjectId}/requests/{item.Id}",
stringContent);

if (result.IsSuccessStatusCode)
{
Expand All @@ -79,6 +83,5 @@ public InternalCollection(IEnumerable<T> items)

public IEnumerable<T> Value { get; set; }
}

}
}
}

0 comments on commit 9a81266

Please sign in to comment.