У меня есть приложение Azure Logic, использующее шаблон poll-async, но конечная точка проверки состояния никогда не вызывается, даже если она работает нормально при вызове из PostMan.
Приложение логики в Azure настроено для поддержки асинхронного шаблона, и начальная конечная точка возвращает заголовок расположения с правильным путем для конечной точки проверки состояния.
Вот пример кода
//State dictionary for sample - stores the state of the working thread
private static Dictionary<int, bool> runningTasks = new Dictionary<int, 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("startwork")]
public async Task<HttpResponseMessage> longrunningtask(int FileId)
{
runningTasks[FileId] = false; //Job isn't done yet
new Thread(() => ImportFileDataFromLogicAppRequest(FileId)).Start(); //Start the thread of work, but continue on before it completes
HttpResponseMessage responseMessage = new HttpResponseMessage(HttpStatusCode.Accepted);
responseMessage.Headers.Add("location", String.Format("{0}://{1}/api/SocialNetworks/Facebook/status/{2}", Request.Scheme, Request.Host, FileId)); //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>
/// 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("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(int id)
{
//If the job is complete
if (runningTasks.ContainsKey(id) && runningTasks[id])
{
runningTasks.Remove(id);
return new HttpResponseMessage(HttpStatusCode.OK)
{ ReasonPhrase = "Some data could be returned here" };
}
//If the job is still running
else if (runningTasks.ContainsKey(id))
{
HttpResponseMessage responseMessage =
new HttpResponseMessage(HttpStatusCode.Accepted);
responseMessage.Headers.Add("location", String.Format("{0}://{1}/api/SocialNetworks/Facebook/status/{2}",
Request.Scheme, Request.Host, id)); //Where the engine will poll to check status
responseMessage.Headers.Add("retry-after", "20");
return responseMessage;
}
else
{
return new HttpResponseMessage(HttpStatusCode.BadRequest)
{
ReasonPhrase = "No job exists with the specified ID"
};
}
}
/// <summary>
/// Imports file data from a request comming from a Logic App
/// </summary>
/// <param name="FileId"></param>
/// <returns></returns>
//[HttpPost]
//[Route("ImportFileDataFromLogicAppRequest")]
public async Task ImportFileDataFromLogicAppRequest(int FileId)
{
bool stop = false;
while (!stop)
{
await Task.Delay(50000);
}
runningTasks[FileId] = true;
}
в настоящее время метод длительного запуска имеет бесконечный цикл только для целей отладки, хотя даже если это не так, конечная точка проверки состояния никогда не вызывается.