2

The issue described below doesn't happen on local development, only once I have deployed everything to test environment, which is hosted on Azure Web App.

When calling an API endpoint from Angular (where I use Observer and subscribe on the request), the request is processed and may sometimes take longer than 2 minutes to be processed. When the request hits 2 minutes, I instantly get a 502 bad gateway, while the async process continues until finished.

In the request processing I do a couple of remote powershell script executions, I made sure that both my powershell methods run asynchronously, and made sure that the API endpoint is async. In my angular frontend from where I do the request, I use observer and subscribe on the request being made.

My next step was wanting to make some sort of request that just starts the process, and then somehow be able to keep requesting until I get a response that the response has finished, to avoid the 502 error, but I don't know where or how to start, but I don't know if this approach could even work for sure.

Backend is set up using C#, .NET Core 2.2. Frontend is Angular (7?).

I want to get the expected response instead of hitting 502 Bad Gateway everytime processing hits 2 minutes.

Code:

First I call

this.objectService.processObjectsForMerge(request).subscribe(res => {});

Which, from the service, prepares following request

processObjectsForMerge(req: ProcessObjectsForMergeRequest): Observable<ProcessObjectsForMergeResponse>{
return this.http.post<ProcessObjectsForMergeResponse>(this.API_URL + '/Object/ProcessObjectsForMerge',req, {
  headers: new HttpHeaders({
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + this.auth.getAccessToken()
  })
});

}

And is received in the following endpoint

    [HttpPost]
    [Route("ProcessObjectsForMerge/")]
    public async Task<IActionResult> ProcessObjectsForMerge([FromBody] ProcessMergeRequestModel request)
    {
        if (request == null || string.IsNullOrEmpty(request.VersionNumber) || string.IsNullOrEmpty(request.CuLevel)) return BadRequest("Failed to validate data");

        var permissionGranted = DoesUserHavePermissionForRequest(request.ShortGuid);
        if (!permissionGranted) return BadRequest();

        var isSuccessful = await new ProcessObjectsForMergeService().Process(request);
        var message = !isSuccessful ? "Failed to process objects for merge." : "Successfully processed the objects for merge.";

        return Ok(new {message, log});
    }

Update: I have found a temporary solution, in web.config of the API I was able to increase the timeout time. I feel this is bad practice though, so gonna implement a message queue (using rabbitMQ probably) to execute my initial idea on how to solve it and see if it works out the way I expect.

T-Rex
  • 53
  • 9

0 Answers0