我正在尝试使用Azure Functions解决方案实现文件转换.转换可能需要很长时间.因此,我不希望在呼叫服务器上等待响应.我编写了立即返回响应的函数(表示服务可用并启动转换)并在单独的线程中运行转换.回调URL用于发送转换结果.
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, Stream srcBlob, Binder binder, TraceWriter log)
{
log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");
// Get request model
var input = await req.Content.ReadAsAsync<ConvertInputModel>();
//Run convert in separate thread
Task.Run( async () => {
//Read input blob -> convert -> upload output blob
var convertResult = await ConvertAndUploadFile(input, srcBlob, binder, log);
//return result using HttpClient
SendCallback(convertResult, input.CallbackUrl);
});
//Return response immediately
return req.CreateResponse(HttpStatusCode.OK);
}
Run Code Online (Sandbox Code Playgroud)
新任务破坏绑定的问题.访问params时我遇到异常.那么如何在单独的胎面上进行长时间操作呢?或者这样的解决方案完全错了?