Логические приложения работают до тех пор, пока не возникнет ошибка Http Get Request Parse JSON

В приложениях Microsoft Azure Logic Apps у меня есть цикл do until, который проходит через цикл получения запроса, пока он не будет завершен. Но запрос HTTP Get выдает следующую ошибку, связанную с тайм-аутом. Кажется, что даже при 4 повторных попытках в течение 2 минут время ожидания HTTP-запроса истекает.

BadRequest. Ошибка HTTP-запроса: сервер не ответил в течение установленного времени. См. Ограничения приложения логики на странице https://aka.ms/logic-apps-limits-and-config#http-limits.

ActionFailed. Не удалось выполнить действие. Не удалось выполнить зависимых действий.
Произошло 4 попытки.


До разработки Loop Control


введите описание изображения здесь

введите описание изображения здесь


person R2D2    schedule 09.02.2021    source источник
comment
Если у вас есть другие вопросы, дайте мне знать.   -  person Frank Gong    schedule 11.02.2021
comment
Да, можно ли сделать видео-демонстрацию того, как установить код? Я новичок в приложениях логики. Может быть, видео на YouTube. Просто показываю, как и где установить свой код?   -  person R2D2    schedule 12.02.2021


Ответы (1)


Если он по-прежнему не работает после включения Asynchronous Pattern, это должно быть связано с тем, что вы не разработали свой API в соответствии с asynchronous polling pattern.

введите описание изображения здесь

Из этого изображения вы можете узнать, что ваш API должен сначала вернуть 202, а заголовок ответа должен содержать location, этот location является URL-адресом, опрошенным приложением логики Azure.

См. следующий образец, но этот образец может быть немного устаревшим, вы можете обратиться к нему, чтобы разработать свой API.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;

namespace AsyncResponse.Controllers
{
    public class AsyncController : ApiController
    {
        //State dictionary for sample - stores the state of the working thread
        private static Dictionary<Guid, bool> runningTasks = new Dictionary<Guid, bool>();


        /// <summary>
        /// This is the method that starts the task running.  It creates a new thread to complete the work on, and returns an ID which can be passed in to check the status of the job.  
        /// In a real world scenario your dictionary may contain the object you want to return when the work is done.
        /// </summary>
        /// <returns>HTTP Response with needed headers</returns>
        [HttpPost]
        [Route("api/startwork")]
        public async Task<HttpResponseMessage> longrunningtask()
        {
            Guid id = Guid.NewGuid();  //Generate tracking Id
            runningTasks[id] = false;  //Job isn't done yet
            new Thread(() => doWork(id)).Start();   //Start the thread of work, but continue on before it completes
            HttpResponseMessage responseMessage = Request.CreateResponse(HttpStatusCode.Accepted);   
            responseMessage.Headers.Add("location", String.Format("{0}://{1}/api/status/{2}", Request.RequestUri.Scheme, Request.RequestUri.Host, id));  //Where the engine will poll to check status
            responseMessage.Headers.Add("retry-after", "20");   //How many seconds it should wait (20 is default if not included)
            return responseMessage;
        }


        /// <summary>
        /// This is where the actual long running work would occur.
        /// </summary>
        /// <param name="id"></param>
        private void doWork(Guid id)
        {
            Debug.WriteLine("Starting work");
            Task.Delay(120000).Wait(); //Do work will work for 120 seconds)
            Debug.WriteLine("Work completed");
            runningTasks[id] = true;  //Set the flag to true - work done
        }

        /// <summary>
        /// Method to check the status of the job.  This is where the location header redirects to.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("api/status/{id}")]
        [Swashbuckle.Swagger.Annotations.SwaggerResponse(HttpStatusCode.BadRequest, "No job exists with the specified id")]
        [Swashbuckle.Swagger.Annotations.SwaggerResponse(HttpStatusCode.Accepted, "The job is still running")]
        [Swashbuckle.Swagger.Annotations.SwaggerResponse(HttpStatusCode.OK, "The job has completed")]
        public HttpResponseMessage checkStatus([FromUri] Guid id)
        {
            //If the job is complete
            if(runningTasks.ContainsKey(id) && runningTasks[id])
            {
                runningTasks.Remove(id);
                return Request.CreateResponse(HttpStatusCode.OK, "Some data could be returned here");
            }
            //If the job is still running
            else if(runningTasks.ContainsKey(id))
            {
                HttpResponseMessage responseMessage = Request.CreateResponse(HttpStatusCode.Accepted);
                responseMessage.Headers.Add("location", String.Format("{0}://{1}/api/status/{2}", Request.RequestUri.Scheme, Request.RequestUri.Host, id));  //Where the engine will poll to check status
                responseMessage.Headers.Add("retry-after", "20");
                return responseMessage;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No job exists with the specified ID");
            }
        }
    }
}
person Frank Gong    schedule 10.02.2021
comment
Можно ли сделать видео-демонстрацию того, как установить код? Я новичок в приложениях логики. Может быть, видео на YouTube. Просто показываю, как и где установить свой код? - person R2D2; 12.02.2021