简体   繁体   中英

Long running task api call from logic app to avoid timeout bad request response after many retiries in .Net Core 3.0

I have an azure api app exposing some business apis. I need to implement Long running task strategy because I want to call one of these apis from my Logic App because that api takes more than 2 minutes (which is the request timeout limit ) to respond.

I have read the documentation of Microsoft and I also tried the git sample provided here . Unfortunately, that didn't help me much because the samples on git are not very explicit and not compatible with .Net Core 3.0.

So, Actually, I am using asp net core 3.0. using DI and async calls in my app. Here an example of a controller api that I want to test

        [HttpGet]
        [Route("PollDataIntoProduction")]
        public async Task<IActionResult> PrePollData()
        {
            await _pollingService.ProduceData();
            return Ok($"Polling Execution Success at {DateTime.Now}");
        }

_pollingService is the service injected with DI that does the work for me and is async

And here is an http call example inside my logic app (which taking more than 2 minutes and causing bad request and timeout )

在此处输入图像描述

Can anyone provide me a working code sample with.Net Core 3.0 on how I can effectively implement the webhook pattern to wait for my api to finish processing in my logic app please?

Thank you in advance,

There are 2 ways to approach this

  1. WebHook Pattern
    For this you will have to use the WebHook action , which calls a subscription API triggering the asynchronous job in the background. This job would have to call the callback Url passed along with the subscribe API call.

    In your code, instead of await ing the pollingService method, you would call it directly by passing in the callbackUrl passed from the Logic App and later call that URL once ready.

  2. Async Pattern
    For this you will have to use the HTTP action with asynchronous pattern enabled in its settings. This would make the call to your service which returns a 202 Accepted response with a status URL set in the location header, which the Logic App will poll until completion.

    If you are using Azure Functions, the Durable Functions Async Pattern is a perfect fit for this.

    In ASP.NET Core, apart from responding with a 202 Accepted with the appropriate location header, you would have to implement a status endpoint which checks the progress of the background task.

    Also, if your service is scaled out to multiple instances, you would need to implement using external store, like Redis, for maintaining the status of such jobs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM